Skip to content

Instantly share code, notes, and snippets.

@upangka
Created December 27, 2019 02:42
Show Gist options
  • Save upangka/ef723733934ffb614f183a8881de6caa to your computer and use it in GitHub Desktop.
Save upangka/ef723733934ffb614f183a8881de6caa to your computer and use it in GitHub Desktop.
将数字字符串变成list,并将每个值乘以2
package org.caucoder.nullex;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* 两个map使用
*/
public class StreamMap {
public static void main(String[] args) {
String str = "1,2,3";
List<Integer> res = Arrays.stream(str.split(","))
.map(Integer::parseInt)
.map(StreamMap::Double).collect(Collectors.toList());
System.out.println(res);
}
public static Integer Double(Integer i){
return i*2;
}
}
/**
[2, 4, 6]
*/
@upangka
Copy link
Author

upangka commented Dec 27, 2019

StreamMap::Double 而不是 this::Double

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment