Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.mycompany.app9;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- import java.util.stream.Stream;
- /**
- *
- * @author Admin
- */
- public class Main {
- //
- public static void main(String[] args) {
- //
- List<String> list = new ArrayList<>();
- list.add("array1");
- list.add("array2");
- list.stream().forEach(System.out::println);
- //
- Stream<String> s = list.stream();
- s.forEach(System.out::println);
- //s.forEach(System.out::println);
- //
- System.out.println("Iterator for List:");
- Iterator<String> i = list.iterator();
- while(i.hasNext()){
- String value = i.next();
- System.out.println("value=" + value);
- }
- System.out.println("Iterator for Stream:");
- Iterator<String> i1 = list.stream().iterator();
- while(i1.hasNext()){
- String value1 = i1.next();
- System.out.println("stream.value=" + value1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement