从对象集合中过滤并拼接需要的串
String skus = productList.stream()
.filter(product -> !StringUtil.isBlank(product.getGoodsCode()))
.map(ScsTopProductStock::getGoodsCode)
.collect(Collectors.joining(","));
集合转字符串的两种方式
List<String> cities = Arrays.asList("Milan", "London", "New York", "San Francisco"); String citiesCommaSeparated = String.join(",", cities); System.out.println(citiesCommaSeparated);
String citiesCommaSeparated = cities.stream() .collect(Collectors.joining(",")); System.out.println(citiesCommaSeparated);
集合累加
public static void main(String[] args) { List<Integer> list = Arrays.asList(1,2,3,4,6,0); Integer sum = list.stream() .filter(item -> item != 0) .mapToInt(Integer::intValue) .sum(); System.out.println(sum); }