Java 8 | Fetch top N unique numbers from list

Below Java 8 example shows how to fetch top N unique numbers from ArrayList.

Traditional looping will require more logic to first remove duplicates, sort numbers and then store N numbers to different list.

Java 8 provides stream API to do all the above steps in single line of code. 

Descending order (N = 3)


Ascending order (N = 3)

Comments

Popular posts from this blog

Spring | Using TIBCO EMS with Spring framework

TIBCO | For Loop - Accumulate output

TIBCO | JNDI Server & JMS Instance creation