Example :
package com.demo.java8; import java.util.Arrays; import java.util.List; public class Demo6 { public static void main(String[] args) { List<Emp6> empList = Arrays.asList(new Emp6[] { new Emp6("1","Mumbai","20"), new Emp6("2","Delhi","23"), new Emp6("3","Kolkata","25"), new Emp6("4","Chennai","18"), new Emp6("9","Delhi","22"), new Emp6("5","Mumbai","11"), new Emp6("6","Kolkata","30"), new Emp6("7","Chennai","35"), new Emp6("8","Mumbai","15"), new Emp6("3","Kolkata","25"), new Emp6("6","Kolkata","30"), new Emp6("9","Delhi","22"), new Emp6("10","Kolkata","27") }); empList.stream().map(x->x.getId()).distinct().sorted((e1,e2) -> Integer.parseInt(e1)-Integer.parseInt(e2)).forEach(System.out::println); } } class Emp6{ private String id; private String city; private String age; public Emp6(String id, String city, String age) { super(); this.id = id; this.city = city; this.age = age; } public String getId() {return id;} public String getCity() {return city;} public String getAge() {return age;} @Override public String toString() { return "Emp [id=" + id + ", city=" + city + ", age=" + age + "]"; } }