sergAccount

Untitled

Feb 6th, 2021
495
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.mycompany.app9;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Iterator;
  10. import java.util.List;
  11. import java.util.Set;
  12. import java.util.stream.Collectors;
  13. import java.util.stream.Stream;
  14.  
  15. /**
  16.  *
  17.  * @author Admin
  18.  */
  19. public class Main {    
  20.     //
  21.     public static void main(String[] args) {
  22.         //
  23.         List<String> list = new ArrayList<>();
  24.         list.add("array1");
  25.         list.add("array2");
  26.         list.stream().forEach(System.out::println);
  27.         //
  28.         Stream<String> s = list.stream();
  29.         s.forEach(System.out::println);
  30.         //s.forEach(System.out::println);                
  31.         //
  32.         System.out.println("Iterator for List:");
  33.         Iterator<String> i = list.iterator();
  34.         while(i.hasNext()){
  35.             String value = i.next();
  36.             System.out.println("value=" + value);
  37.         }                
  38.         System.out.println("Iterator for Stream:");
  39.         Iterator<String> i1 = list.stream().iterator();
  40.         while(i1.hasNext()){
  41.             String value1 = i1.next();
  42.             System.out.println("stream.value=" + value1);
  43.         }
  44.         System.out.println("PRINT STREAM ELEMENTS:");
  45.         // использование метода of для создания потока Stream
  46.         Stream<String> s3 = Stream.of("ONE", "TWO");
  47.         s3.forEach(System.out::println);
  48.        
  49.         System.out.println("collect - method (toList):");
  50.         Stream<String> s4 = Stream.of("ONE", "TWO");
  51.         // использовние метода collect и класса Collectors
  52.         List<String> result = s4.collect(Collectors.toList());
  53.         for(String val: result){
  54.             System.out.println("val=" + val);
  55.         }
  56.         System.out.println("collect - method (toSet):");
  57.         Stream<String> s5 = Stream.of("ONE", "TWO", "ONE");
  58.         // использовние метода collect и класса Collectors
  59.         Set<String> result2 = s5.collect(Collectors.toSet());
  60.         for(String val: result2){
  61.             System.out.println("val2=" + val);
  62.         }
  63.     }    
  64. }
  65.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×