I am trying to achieve below logic using Lambda-Stream in Java 8. (See below sample method). I put down below logic in old fashion so that it will be easy to create solution instead of my version of Lambda - Stream setup which is more complex and wrong as not getting end result.
public static HashMap<EnumObj,String> getHashMapData(String…args){
int i = 0;
HashMap<EnumObj,String> hashObj = new HashMap<EnumObj,String>();
if(args.length <= 6){
for(String arg : args){
if(i == 0){
hashObj.put(EnumObj.FIRSTNAME,args[i]);
}else if(i == 1){
hashObj.put(EnumObj.LASTNAME,args[i]);
}else if{……….
………….
}else if(i == 4 && args.length < 5){
hashObj.put(EnumObj.COMPANY,args[i]);
hashObj.put(EnumObj.COMANYBOSS,args[i+1]);
}else if(i == 5 && args.length < 6){
hashObj.put(EnumObj.COMANYBOSS,args[i]);
}
}
}
}
Please ignore any lopping logic of if / else if as time ago lost touch of such looping logic. While I am keep trying on my logic thought Got to get some idea if someone else has done successfully or have suggestion to achieve it with simplest manner.
So far I use two Stream
to achieve with Collections.toMap
option for creating new map. But it has Stream with in a stream and more complex.
If I found solution by my self then will post that answer otherwise will vote for best solution.