Is there a way to change this?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zerofury
    New Member
    • Jun 2007
    • 9

    Is there a way to change this?

    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?
  • Zerofury
    New Member
    • Jun 2007
    • 9

    #2
    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?

    Comment

    • Zerofury
      New Member
      • Jun 2007
      • 9

      #3
      Or here is another idea. How can i set the itemNumber field to reflect the array position of that object?

      Comment

      • Zerofury
        New Member
        • Jun 2007
        • 9

        #4
        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

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by Zerofury
          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 :)
          Nice work

          Comment

          Working...