Maximus
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
public static void main(String[] args) {
// TODO Auto-generated method stub
String test="avscfaabc";
String test1="abcdrst";
String test2="aasabcdfs";
String test3="vbabcsdr";
Map<String,Integer> map=new HashMap<String,Integer>();
map.put(test, test.indexOf("abc"));
map.put(test1, test1.indexOf("abc"));
map.put(test2, test2.indexOf("abc"));
map.put(test3, test3.indexOf("abc"));
Map<String,Integer> sortedNewMap = map.entrySet().stream().sorted((e1,e2)-> e1.getValue().compareTo(e2.getValue()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,(e1, e2) -> e1, LinkedHashMap::new));
sortedNewMap.forEach((key,val)->{
System.out.println(key+ " = "+ val.toString());
});
}
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
- Maximus February 28, 2017