List<String> stringList = new ArrayList<>();
stringList.add("a11");
stringList.add("b11");
stringList.add("c11");
stringList.add("d11");
stringList.add("e11");
List<Map<String,String>> stringList1 = stringList.stream().map(item->
{
Map<String,String> map = new HashMap<>();
map.put("name", item.toUpperCase());
return map;
}
).collect(Collectors.toList());
List<Long> longList = new ArrayList<>();
longList.add(1L);
longList.add(2L);
longList.add(3L);
List<String> stringList = longList.stream().map(item -> String.valueOf(item.intValue())).collect(Collectors.toList());
System.out.println(stringList);
List<User> userList = new LinkedList<>();
Map<Integer,User> userMap = userList.
stream().
collect(Collectors.toMap(
item -> item.getId(),
item-> item,
(v1,v2)->v1
));
Map<Integer,User> userMap1 = userList.
stream().
collect(Collectors.toMap(
item -> item.getId(),
Function.identity()));
List<Integer> sourceList = new ArrayList<>();
List<String> targetList = sourceList.stream().
map(String::valueOf).collect(Collectors.toList());
List<String> sourceList = new ArrayList<>();
List<Integer> targetList = sourceList.stream().
map((str -> Integer.parseInt(str))).collect(Collectors.toList());
List<String> sourceList = new ArrayList<>();
String targetStr = String.join(",",sourceList );
List<String> targetList = Arrays.asList(targetStr.split(","));
List<Integer> intList = new ArrayList<>();
for(int i=0;i<100000;i++) {
intList.add(i);
}
long t1 = System.currentTimeMillis();
List<String> collect = intList.stream().map(integer1 -> integer1 + "key").collect(Collectors.toList());
long t2 = System.currentTimeMillis();
List<String> collect1 = intList.parallelStream().map(integer1 -> integer1 + "key").collect(Collectors.toList());
long t3 = System.currentTimeMillis();
System.out.println("---串行:"+(t2-t1));
System.out.println("---并行:"+(t3-t2));
|