Пример #1
0
 public Collection<Integer> getRtcWorkItemRange() {
   String rangesString = props.getProperty(RTC_WORKITEM_ID_RANGE);
   String[] ranges = rangesString.split(",");
   IntStream intStream = IntStream.of();
   for (String range : ranges) {
     String[] splitted = range.split("\\.\\.");
     int from = Integer.parseInt(splitted[0].trim());
     if (splitted.length == 1) {
       intStream = IntStream.concat(intStream, IntStream.rangeClosed(from, from));
     } else {
       int to = Integer.parseInt(splitted[1].trim());
       intStream = IntStream.concat(intStream, IntStream.rangeClosed(from, to));
     }
   }
   return intStream.boxed().collect(Collectors.toList());
 }
Пример #2
0
  public static void main(String[] args) {
    List<Dish> menu =
        Arrays.asList(
            new Dish("pork", false, 800, Dish.Type.MEAT),
            new Dish("beef", false, 700, Dish.Type.MEAT),
            new Dish("chicken", false, 400, Dish.Type.MEAT),
            new Dish("french fries", true, 530, Dish.Type.OTHER),
            new Dish("rice", true, 350, Dish.Type.OTHER),
            new Dish("prawns", false, 300, Dish.Type.FISH));

    IntStream intStream = menu.stream().mapToInt(Dish::getCalories);

    int calories =
        intStream // IntStream으로 변환
            .sum();

    Stream<Integer> boxedStream = intStream.boxed(); // 숫자 스트림을 스트림으로 변환
  }