Advertisement
sergAccount

Untitled

Feb 14th, 2021
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 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.ja11;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Collection;
  10. import java.util.Iterator;
  11. import java.util.List;
  12.  
  13. public class Main3 {
  14.    
  15.     public static void main(String[] args) {
  16.        
  17.         Collection<String> s;        
  18.         // Collection s2;
  19.         List<Integer> list;
  20.        
  21.         List<String> list2 = new ArrayList<>();
  22.         list2.add("ONE");        
  23.         String value = list2.get(0);
  24.         System.out.println("value=" + value);
  25.        
  26.         List<Person> list3 = new ArrayList<>();
  27.         list3.add(new Person());
  28.         list3.add(new Person());
  29.         list3.add(new Person());  
  30.         // получаем объект типа Iterator
  31.         Iterator<String> i = list2.iterator();
  32.         System.out.println("i.hasNext()=" + i.hasNext());
  33.         // Ctrl+Shift+I
  34.         // получаем все элементы коллекции и выводим их на экран - используем интерфейс Iterator
  35.         while(i.hasNext()){
  36.             String val = i.next();
  37.             System.out.println("val=" + val);
  38.         }
  39.        
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement