If i have an arraylist, and i want it resorted by alpha, how can i have people do a search for an item by Item Number field, instead of by array position?
Is there a way to change this?
Collapse
X
-
I've thought of a way to do this, but i'm not sure how this will turn out.
If in my item class i implement the compareTo method, and do one by name field, what happens if i put a second one in as well by number?
Is there a way in my Inventory program to tell it which one to use?
i'm using the Collections.sor t(OBJECTNAME);
is there a way to specify a sort by name, and then a new sort by number, to reorder the list by item number, then allow them to search for individual items by item number? -
Never mind. I found a way around it.
Instead of resorting or displaying a fixed item number, instead I had it print the line "item number: <choice>" where choice was the item they wished to view. Because choice corresponds always to the array position, it is always accurate. After the reorder with the alpha sorter, the position changes, and so does the item number to reflect that, thus it stays accurate and the two match. Then, when i had it print the entire list, since each pass through the loop cooresponded to the item number and array position, i just had it print a line displaying the loop iteration and called it "Item Number: <counter>". So in essence, it LOOKS like it's part of it, but it's not, yet the text always reflects correctly.
It was so simple i couldn't see it :)Comment
-
Originally posted by ZerofuryNever mind. I found a way around it.
Instead of resorting or displaying a fixed item number, instead I had it print the line "item number: <choice>" where choice was the item they wished to view. Because choice corresponds always to the array position, it is always accurate. After the reorder with the alpha sorter, the position changes, and so does the item number to reflect that, thus it stays accurate and the two match. Then, when i had it print the entire list, since each pass through the loop cooresponded to the item number and array position, i just had it print a line displaying the loop iteration and called it "Item Number: <counter>". So in essence, it LOOKS like it's part of it, but it's not, yet the text always reflects correctly.
It was so simple i couldn't see it :)Comment
Comment