Skip to content

A simple Java class that provides natural sorting for strings.

License

Notifications You must be signed in to change notification settings

jagobagascon/Natural-Sorting-for-Java

Repository files navigation

Natural Sorting for Java

A simple Java class that provides natural sorting for strings.

Usage

Step 1 Add the GitHub Maven repository to your build file

<repositories>
	<repository>
		<id>github</id>
		<url>https://maven.pkg.github.com/jagobagascon</url>
		<snapshots>
			<enabled>true</enabled>
		</snapshots>
	</repository>
</repositories>

Step 2 Add the dependency

<dependency>
    <groupId>com.github.jagobagascon</groupId>
    <artifactId>Natural-Sorting-for-Java</artifactId>
    <version>1.2.0</version>
</dependency>

Step 3 Use the provided comparators to sort your lists

// If < JDK 8 use: Collections.sort

public void sortNatural(List<String> myList) {
	myList.sort(NaturalSort.naturalSortComparator);
}

public void sortNaturalIgnoreCase(List<String> myList) {
	myList.sort(NaturalSort.naturalSortIgnoreCaseComparator);
}

Notes

The library recognizes non-ASCII decimal digits when comparing numbers (for example, Thai digits or full-width digits). Numbers consisting of mixed digit sets or languages are compared as a whole. See this discussion for more info.

About

A simple Java class that provides natural sorting for strings.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages