Skip to Content
Java Coding Problems
book

Java Coding Problems

by Anghel Leonard
September 2019
Intermediate to advanced
816 pages
18h 47m
English
Packt Publishing
Content preview from Java Coding Problems

Lexicographical comparison

If all we want is a lexicographical comparison of the paths, then we can rely on the Path.compareTo() method (this can be useful for sorting).

This method returns the following information:

  • 0 if the paths are equal
  • A value less than zero if the first path is lexicographically less than the argument path
  • A value greater than zero if the first path is lexicographically greater than the argument path:
int path1compareToPath2 = path1.compareTo(path2); // 0int path1compareToPath3 = path1.compareTo(path3); // 24int path2compareToPath3 = path2.compareTo(path3); // 24

Note that you may obtain different values than in the preceding example. Furthermore, in your business logic, it is important to rely on their meaning and ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Coding Problems - Second Edition

Java Coding Problems - Second Edition

Anghel Leonard
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
The Well-Grounded Java Developer, Second Edition

The Well-Grounded Java Developer, Second Edition

Benjamin Evans, Martijn Verburg, Jason Clark

Publisher Resources

ISBN: 9781789801415Supplemental Content