Here you can find the source of equals(Collection
private static <T> boolean equals(Collection<T> a, Collection<T> b, boolean ordered)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { private static <T> boolean equals(Collection<T> a, Collection<T> b, boolean ordered) { if (a == null) return b == null; else if (b == null) return a == null; else if (a.size() != b.size()) return false; else if (ordered) return a.equals(b); else {//from w w w . j a va2 s. c o m List<T> list = new ArrayList<T>(a); for (T t : b) { if (!list.remove(t)) return false; } return true; } } }