Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.ListIterator;
- import java.util.TreeSet;
- public class Main {
- public static void main(String[] args) {
- ArrayList<Employee> list = new ArrayList<Employee>();
- list.add(new Employee("Vasya", "Pupkin"));
- list.add(new Employee("Petya", "Pipetkin"));
- list.add(new Employee("Leonid", "Space"));
- for (Employee a:list){
- System.out.println(a);
- }
- System.out.println();
- Iterator<Employee> it = list.iterator();
- while (it.hasNext()){
- System.out.println(it.next());
- }
- ListIterator<Employee> lit= list.listIterator();
- // while (lit.hasNext()){
- // Employee elem = lit.next();
- // elem.setName("NewName");
- // // elem.setSurname("NewSurname");
- // lit.set(elem);
- // }
- System.out.println();
- lit = list.listIterator();
- while (lit.hasNext()){
- System.out.println(lit.next());
- }
- System.out.println();
- while (lit.hasPrevious()){
- System.out.println(lit.previous());
- }
- TreeSet<Employee> ts = new TreeSet<Employee>();
- it = list.iterator();
- while (it.hasNext()){
- ts.add(it.next());
- }
- System.out.println();
- it = ts.iterator();
- while (it.hasNext()){
- System.out.println(it.next());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement