Path normalize() method in Java with Examples Last Updated : 30 Jul, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The normalize() method of java.nio.file.Path used to return a path from current path in which all redundant name elements are eliminated. The precise definition of this method is implementation dependent and it derives a path that does not contain redundant name elements. In many file systems, the "." and ".." are special names indicating the current directory and parent directory. In those cases all occurrences of "." are considered redundant and If a ".." is preceded by a non-".." name then both names are considered redundant. Syntax: Path normalize() Parameters: This method accepts nothing. It is parameter less method. Return value: This method returns the resulting path or this path if it does not contain redundant name elements; an empty path is returned if this path does not have a root component and all name elements are redundant. Below programs illustrate normalize() method: Program 1: Java // Java program to demonstrate // java.nio.file.Path.normalize() method import java.nio.file.*; public class GFG { public static void main(String[] args) { // create object of Path // In this example \\.. starts with non".." // element Path path = Paths.get("D:\\..\\..\\.\\p2\\core" + "\\cache\\binary"); // print actual path System.out.println("Actual Path : " + path); // normalize the path Path normalizedPath = path.normalize(); // print normalized path System.out.println("\nNormalized Path : " + normalizedPath); } } Output: Program 2: Java // Java program to demonstrate // java.nio.file.Path.normalize() method import java.nio.file.*; public class GFG { public static void main(String[] args) { // create object of Path Path path = Paths.get("\\.\\.\\core" + "\\file\\binary.java"); // print actual path System.out.println("Actual Path : " + path); // normalize the path Path normalizedPath = path.normalize(); // print normalized path System.out.println("\nNormalized Path : " + normalizedPath); } } Output: References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Path.html#normalize() Comment More infoAdvertise with us Next Article Path toAbsolutePath() 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 Period normalized() method in Java with Examples The normalized() method of Period class in Java is used to return a new instance of Period after normalizing years and months. Syntax: public Period normalized() Parameters: This function does not accepts any parameter. Return Value: This function returns a new instance of Period after normalizing y 2 min read Path subpath() method in Java with Examples The subpath(int beginIndex, int endIndex) method of java.nio.file.Path used to return a relative Path that is a subsequence of the name elements of this path. We will pass begin and end indexes to construct a subpath. The beginIndex and endIndex parameters specify the subsequence of name elements. T 2 min read Path toAbsolutePath() method in Java with Examples The Java Path interface was added to Java NIO in Java 7. toAbsolutePath() method of java.nio.file.Path used to return a Path object representing the absolute path of this path object. If the path is already absolute then the method returns path else this method resolves this path in an implementatio 2 min read Vector trimToSize() method in Java with Example The trimToSize() method of Vector in Java trims the capacity of an Vector instance to be the Vector's current size. This method is used to trim an Vector instance to the number of elements it contains. Syntax: trimToSize() Parameter: It does not accepts any parameter. Return Value: It does not retur 2 min read 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 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 Like