Java tutorial
//package com.java2s; import java.util.*; public class Main { /** * Compare if two iterable objects are equal by element. * @param i1 sequence 1. * @param i2 sequence 2. * @param <T> type. * @return true if all elements at the same index are equal. */ public static <T> boolean iterableEquals(Iterable<T> i1, Iterable<T> i2) { if (Objects.equals(i1, i2)) return true; if (i1 == null || i2 == null) return false; Iterator<T> iterator1 = i1.iterator(); Iterator<T> iterator2 = i2.iterator(); while (iterator1.hasNext()) { if (!iterator2.hasNext()) return false; T obj1 = iterator1.next(); T obj2 = iterator2.next(); if (!Objects.equals(obj1, obj2)) { return false; } } return !iterator2.hasNext(); } }