for simplicity I have 2 lists of String and I need to join the strings into one and create another list.
For eg --
List 1 = [a,b,c,d]
List 2 = [e,f,g,h]
I want the output as
List3 = [ae,bf,cg,dh]
I can do this using regular for loops. but dont know how to proceed for java8
I am trying to get myself thinking in n Java 8 :-)
解决方案
I'm not sure there's a better (easy) way to do this than to access the elements from the two lists by index:
List zipped = IntStream.range(0, list.size())
.mapToObj(i -> list1.get(i) + list2.get(i))
.collect(Collectors.toList());