Advertisement
sergAccount

Untitled

Feb 6th, 2021
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  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.stream.Stream;
  12.  
  13. /**
  14.  *
  15.  * @author Admin
  16.  */
  17. public class Main {    
  18.     //
  19.     public static void main(String[] args) {
  20.         //
  21.         List<String> list = new ArrayList<>();
  22.         list.add("array1");
  23.         list.add("array2");
  24.         list.stream().forEach(System.out::println);
  25.         //
  26.         Stream<String> s = list.stream();
  27.         s.forEach(System.out::println);
  28.         //s.forEach(System.out::println);                
  29.         //
  30.         System.out.println("Iterator for List:");
  31.         Iterator<String> i = list.iterator();
  32.         while(i.hasNext()){
  33.             String value = i.next();
  34.             System.out.println("value=" + value);
  35.         }                
  36.         System.out.println("Iterator for Stream:");
  37.         Iterator<String> i1 = list.stream().iterator();
  38.         while(i1.hasNext()){
  39.             String value1 = i1.next();
  40.             System.out.println("stream.value=" + value1);
  41.         }
  42.     }    
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement