Path toString() method in Java with Examples Last Updated : 14 Apr, 2023 Comments Improve Suggest changes Like Article Like Report The Java Path interface was added to Java NIO in Java 7. toString() method of java.nio.file.Path used to return the string representation of this path. If this path was created by converting a path string using the getPath method then the path string returned by this method may differ from the original String used to create the path. The returned path by this method uses the default name-separator to separate names in the path. Syntax: String toString() Parameters: This method accepts nothing. Return value: This method returns the string representation of this path. Below programs illustrate toString() method: Program 1: Java // Java program to demonstrate // java.nio.file.Path.toString() method import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; public class GFG { public static void main(String[] args) throws IOException { // create object of Path Path path = Paths.get("C:\\Program Files\\" + "Java\\jre1.8.0_211"); // print path System.out.println("Path: " + path.toString()); } } Output:Path: C:\Program Files\Java\jre1.8.0_211 Program 2: Java // Java program to demonstrate // java.nio.file.Path.toString() method import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; public class GFG { public static void main(String[] args) throws IOException { // create object of Path Path path = Paths.get("C:\\Users\\" + "asingh.one\\Documents"); // print path System.out.println("Path: " + path.toString()); } } Output:Path: C:\Users\asingh.one\Documents References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Path.html#toString() Comment More infoAdvertise with us Next Article Path toString() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-Path java.nio.file package Practice Tags : Java Similar Reads Path toUri() method in Java with Examples The toUri() method of java.nio.file.Path interface used to return a URI to represent this path. This method converts this path into an absolute URI with a scheme equal to the URI scheme that identifies the provider. The exact form of the scheme-specific part is highly provider dependent. In the scen 2 min read Pattern toString() Method in Java with Examples toString() method of a Pattern class used to return the string representation of this pattern. This return the regular expression from which this pattern was compiled. Syntax: public String toString() Parameters: This method accepts nothing as parameter. Return value: This method returns a string re 1 min read Package toString() method in Java with Examples The toString() method of java.lang.Package class is used to get the String representation of this package instance. The method returns the String representation as a String value. Syntax: public String toString() Parameter: This method does not accepts any parameter. Return Value: This method return 1 min read String toString() Method in java with Examples String toString() is the built-in method of java.lang which return itself a string. So here no actual conversion is performed. Since toString() method simply returns the current string without any changes, there is no need to call the string explicitly, it is usually called implicitly. Syntax : publ 1 min read Scanner toString() method in Java with Examples The toString() method of java.util.Scanner class returns the string representation of this Scanner. The exact format is unspecified. Syntax: public String toString() Return Value: This function returns the string representation of this scanner. Below program illustrates the above function: Program 1 1 min read Path toFile() method in Java with Examples The toFile() method of java.nio.file.Path interface used to return a java.io.File object representing this path object. if this Path is associated with the default provider, then this method returns a java.io.File object constructed with the String representation of this path. If this path was creat 2 min read Stack toString() method in Java with Example The toString() method of Java Stack is used to return a string representation of the elements of the Collection. The String representation comprises a set representation of the elements of the Collection in the order they are picked by the iterator closed in square brackets[].This method is used mai 2 min read String replace() method in Java with Examples The String replace() method returns a new string after replacing all the old characters/CharSequence with a given character/CharSequence. Example:Return a new string where all " o" characters are replaced with "p" character: Java // Java program to demonstrate // the replace() method public class Ma 4 min read Provider toString() method in Java with Examples The toString() method of java.security.Provider class is used to return a string with the name and the version number of this provider. Syntax: public String toString() Return Value: This method returns the string with the name and the version number for this provider. Below are the examples to illu 2 min read Like