I have an int stream and want for each element of that stream to do some calculations and return them as Map where keys are int values and values are result of that computat
Here is my code, it will work for you.
Function Reference version
public class AppLauncher {
public static void main(String a[]){
Map map = IntStream.range(1,10).boxed().collect(Collectors.toMap(Function.identity(),AppLauncher::computeSmth));
System.out.println(map);
}
public static Integer computeSmth(Integer i){
return i*i;
}
}
Lambda expression version
public class AppLauncher {
public static void main(String a[]){
Map map = IntStream.range(1,10).boxed().collect(Collectors.toMap(Function.identity(),i->i*i));
System.out.println(map);
}
}