Java examples for Collection Framework:Iterator
equals Iterator
//package com.java2s; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { @SuppressWarnings("unchecked") public static <T> boolean equalsIters(Iterator<T> it1, Iterator<T> it2) { List list1 = new ArrayList(); List list2 = new ArrayList(); while (it1.hasNext()) { list1.add(it1.next());//from w w w .ja va2 s. c o m } while (it2.hasNext()) { list2.add(it2.next()); } return equalsLists(list1, list2); } public static <T> boolean equalsLists(List list1, List list2) { if (list1.size() != list2.size()) { return false; } for (int i = 0; i < list1.size(); ++i) { if (!equals(list1.get(i), list2.get(i))) { return false; } } return true; } public static boolean equals(Object a, Object b) { if (a == null) { return b == null; } return a.equals(b); } }