Skip to content

A simple string comparator in Java for comparing two given values representing software versions constructed by only numbers (0 to 9) and dots as separators

License

Notifications You must be signed in to change notification settings

benjaminsaff/version-number-comparator-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

version-number-comparator Build Status codecov Codacy Badge

A simple string comparator for comparing two given values representing software versions constructed by only numbers (0 to 9) and dots as separators. It compares two strings that are formatted in a typical software version format using only numbers and dots. The comparator assumes only numeric versions are supplied, except for dot separators. There is no limit in length of a string.

Some valid versioning examples

  • 0.0.7
  • 1.3.3.7
  • 6.9
  • 6.0.0.6.5

How to use

When sorting, just pass a comparator instance:

List<String> list = new ArrayList<String>();
list.add("1.2.3.4");
list.add("1.0.2");
...
list.sort(new NumericalVersionComparator());

or just simply use the compare() method in NumericalVersionComparator as needed.

About

A simple string comparator in Java for comparing two given values representing software versions constructed by only numbers (0 to 9) and dots as separators

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages