Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.HashSet; public class Main { public static void uniqe(int[] words, ArrayList<Integer> tempUniqueWords, ArrayList<Integer> tempCounts) { for (int i = 0; i < words.length; i++) { if (tempUniqueWords.contains(words[i])) { int index = tempUniqueWords.indexOf(words[i]); tempCounts.set(index, tempCounts.get(index) + 1); } else { tempUniqueWords.add(words[i]); tempCounts.add(1); } } } public static void uniqe(ArrayList<Integer> items) { // add elements to al, including duplicates HashSet<Integer> hs = new HashSet<Integer>(); hs.addAll(items); items.clear(); items.addAll(hs); } }