Java tutorial
//package com.java2s; //License from project: Apache License import java.util.List; import java.util.ListIterator; public class Main { public static <T> boolean listEquals(List<T> left, List<T> right) { if (left == right) return true; ListIterator<T> leftIterator = left.listIterator(); ListIterator<T> rightIterator = right.listIterator(); while (leftIterator.hasNext() && rightIterator.hasNext()) { T leftElement = leftIterator.next(); T rightElement = rightIterator.next(); if (!(leftElement == null ? rightElement == null : leftElement.equals(rightElement))) return false; } return !(leftIterator.hasNext() || rightIterator.hasNext()); } }