Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java array sorting java8

//1. Natural ordering

User[] sortedUserArray = Stream.of(userArray)
            .sorted()
            .toArray(User[]::new);

//2. Reverse ordering

User[] sortedUserArray = Stream.of(userArray)
            .sorted(Comparator.reverseOrder())
            .toArray(User[]::new);

//3. Custom Sorting

Comparator nameComparator = Comparator.comparing(Employee::getName)
	.thenComparing(Employee::getId)

User[] sortedUserArray = Stream.of(userArray)
            .sorted(nameComparator)
            .toArray(User[]::new);
Comment

PREVIOUS NEXT
Code Example
Java :: how to create a function in java 
Java :: how to create an array without knowing the size java 
Java :: minimum and maximum in array in java 
Java :: java heckj object lock 
Java :: adjust font scale in android studio 
Java :: html alert box android 
Java :: set matrix zeros programming creek 
Java :: latest android version 
Java :: do you need java installed for kafka 
Java :: online java code fixer 
Java :: Java The Throw/Throws Keyword 
Java :: Array List java can I add a pair of element 
Java :: what is exception in java 
Java :: launch java batch 
Java :: Java Converting double into an int 
Java :: write content to file java 
Java :: copy linked list 
Java :: how to do annotation configuration in spring 
Java :: java continue keyword 
Java :: Implementation of LinkedHashMap Class in Java map 
Java :: Java FileOutputStream to write data to a File 
Java :: long to double in java 
Java :: java Math.sqrt(double) 
Java :: pdf intent does not have permission to launch 
Java :: java check if int is null 
Java :: java scanner int to string 
Java :: java array merge 
Java :: java session timeout 
Java :: how to print all package in java 
Java :: switch en java 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =