A good solution what I can suggest here is :
Repeat for each Linked List
1. Convert your linked list into an array by using
<listObject>.toArray() method which returns an Object[]
2. Sort the array using
Arrays.sort(Object[]) with the array you have obtained on step #1
After getting the sorted array equivalent of each linked list,
3. Invoke
Arrays.equals(Object[] array1, Object[] array2) to get to know whether they are equal or not.
Note: The sorting is done based on the natural ordering of elements.
I guess for your linked list of numbers, it would be fine. (so long as it is of built in types like int, float,
String etc., as they have their own ordering well defined in the corresponding classes).
As I am unable to provide the URL for the methods besides each method here, I am pasting those FYI here.
1. List.toArray() ->
http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedList.html#toArray()
2. Arrays.sort() ->
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#sort(java.lang.Object[])
3. Arrays.equals() ->
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#equals(java.lang.Object[], java.lang.Object[])
Hope this helps!