Java tutorial
//package com.java2s; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class Main { public static Integer firstUnique(Collection<Integer> collection) { Map<Integer, Integer> linkedHashMap = new LinkedHashMap<Integer, Integer>(); java.util.Iterator<Integer> it = collection.iterator(); Integer currentInt; java.util.Iterator it1; Set entrySet; Map.Entry<Integer, Integer> me; while (it.hasNext()) { currentInt = it.next(); if (!linkedHashMap.containsKey(currentInt)) { linkedHashMap.put(currentInt, 1); } else { linkedHashMap.put(currentInt, linkedHashMap.get(currentInt) + 1); } } entrySet = linkedHashMap.entrySet(); it1 = entrySet.iterator(); while (it1.hasNext()) { me = (Entry) it1.next(); if (me.getValue().equals(1)) { return (Integer) me.getKey(); } } return null; } }