SortedList<Integer> list = new SortedList<Integer>();
SortedList<Integer> noDuplicates = new SortedList<Integer>(false);
...
int i = Integer.parseInt(str.nextToken());
list.insert(i); // Normal list, the one we're going to use
noDuplicates.insert(i);
...
/* Standard print outs... */
System.out.println("Det fanns " + noDuplicates.size() + " olika tal i filen.");
System.out.println("Nedan anges talen samt antal förekomster inom parantes");
System.out.println();
/* Go through the list, on each element, check how many other exact same elements there is... */
/* Of course, remember to remove the element... */
/* Do always it atleast once for each element... */
Iterator it = list.iterator();
while(it.hasNext()) {
int inc = 0; // Our incrementor...
Object talet = it.next(); // Element
do {
inc++;
it.remove();
} while(it.hasNext() && it.next().equals(talet));
System.out.println(talet + " (" + inc + ')'); // Printing...
it = list.iterator(); // Restore pointer...
}