Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Java Array listing

hi, im a first year computer scientist and im trying to make a java program to solve the 8-puzzle problem. i think i can make everything work except i'm getting confused about array.

everytime i expand a state in the puzzle it produces 2,3 or 4 new states these are all in arrays. i need to make a list of these arrays somehow, so that i can add these new arrays to te top of the list or te bottom, and so its possible to sort the list. i've been wading through websites lookign for a solution but everythign is call abit to general as ive only had 7 weeks of java experience, and havent been told exactly wat an object or a class is yet.

Any help would be appreciated

Thanks
[713 byte] By [Adam_S] at [2007-11-11 7:18:30]
# 1 Re: Java Array listing
If your trying to sort things, try using a TreeSet or other SortedSet interface. You should be able to add stuff like this:

TreeSet<State> set = new TreeSet<State>();

State[] states;

// Code here to get states

set.add(new State());
set.addAll(Arrays.asList(states));

Hope this helps.
evlich at 2007-11-11 22:38:49 >