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.ja11;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Iterator;
- import java.util.List;
- public class Main3 {
- public static void main(String[] args) {
- Collection<String> s;
- // Collection s2;
- List<Integer> list;
- List<String> list2 = new ArrayList<>();
- list2.add("ONE");
- String value = list2.get(0);
- System.out.println("value=" + value);
- List<Person> list3 = new ArrayList<>();
- list3.add(new Person());
- list3.add(new Person());
- list3.add(new Person());
- // получаем объект типа Iterator
- Iterator<String> i = list2.iterator();
- System.out.println("i.hasNext()=" + i.hasNext());
- // Ctrl+Shift+I
- // получаем все элементы коллекции и выводим их на экран - используем интерфейс Iterator
- while(i.hasNext()){
- String val = i.next();
- System.out.println("val=" + val);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement