Articles, dummyCategory

Java Sort on Multiple Fields – Comparator.thenComparing() – HowToDoInJava

Java example to sort list of objects by multiple fields using Comparator.thenComparing() method. This method returns a lexicographic-order comparator with another comparator. It gives the same effect as SQL group by clause. Quick Reference: Group by multiple fields – Example Example of using thenComparing() to create Comparator which is capable of sorting by multiple fields. …

Articles, Home

Java Sort String Characters Alphabetically – HowToDoInJava

Java example to sort characters of String in alphabetical order – using Stream.sorted() and Arrays.sort() methods. 1) Sort string with Stream API Example of sorting the characters of string using Stream.sorted() API. 2) Arrays.sort() Example of sort a string using Arrays.sort() method. Drop me your questions in comments section. Happy Learning !! Reference: Stream.sorted() Java …

Articles, Home

Java Sort Collection – Collections.sort() – HowToDoInJava

Learn to use Collections.sort() method to sort collections in java with examples. By default, this method sorts the unsorted list into ascending order, according to the natural ordering of its elements. 1) Collections.sort( list ) It sorts the specified list into ascending order or their natural order. All elements in the list must implement the …

Articles, Home

Java Sort ArrayList of Objects – HowToDoInJava

Java examples to sort list of objects or primitives (e.g. int, long) using List.sort(), Collections.sort() and sorting with Java stream API. Examples of sorting in natural and reverse order as well. 1) Sort list of objects Examples to sort an arraylist of objects using different sorting techniques. 2) Sort list of primitives Examples to sort …

Articles, Home

Java Stream Collectors – eProgrammerz

Collectors is class an implementations of Collector that implement various useful reduction operations, such as accumulating elements into collections, summarizing elements according to various criteria, etc.

Articles, Home

Java Array Sort – Arrays.sort() Example – HowToDoInJava

Java example to sort an array of primitives and objects which implement Comparable interface. Quick Reference: 1) Sort array of primitives Use Arrays.sort() method to sort an array of primitives such as int, long or String values. 1.1) Sort array in reverse order Use Arrays.sort(arr,Collections.reverseOrder()) to sort an array in reverse oder. 2) Sort array …