473,383 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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?
Jul 2 '07 #1
4 1062
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.sort(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?
Jul 2 '07 #2
Or here is another idea. How can i set the itemNumber field to reflect the array position of that object?
Jul 2 '07 #3
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 :)
Jul 2 '07 #4
r035198x
13,262 8TB
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
Jul 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Scott | last post by:
In the result of a SELECT statement, how can you change cell values from NULL to BLANK? The following does NOT do it: SET fieldname = ' ' WHERE fieldname IS NULL Also, for colums with a DATE...
10
by: TheKeith | last post by:
I don't know much about javascript, so take it easy on me. Is there a way to dynamically change a CSS layers dimensions on the fly. Here is what I'm doing. I have a bunch of thumbnails that when...
18
by: Jan Tuxen | last post by:
Jakob Nielsen in his most recent Alertbox (http://www.useit.com/alertbox/20040503.html) tells web authors to change the color of visited links. I agree to his purpose: Help users understand...
2
by: MLH | last post by:
What's the simplest way to allow a user of an A97 app to change password?
3
by: roger beniot | last post by:
I would like to figure out how to detect an IP address change for an XP/Win2K3 machine that is leasing an IP via DHCP (and do it in C#)... Is there any event that indicates an IP address...
4
by: active | last post by:
It appears to me that if I change the Control's client size the controls size does not change to agree with the new size. Does it work like the VB6 ScaleWidth and ScaleHeight? That is after I...
10
by: Hugh | last post by:
Hi there, An existing solution is used to create a new solution. It is easy to change the names of individual forms and modules. However, how to change the name of project folder? Thanks in...
2
by: Bob Alston | last post by:
I have an application with several forms. Most forms use radio boxes for Yes/No choices. On a few of these, once one option is selected, the user cannot change the selection without moving to...
1
by: eighthman11 | last post by:
Hi everyone: I created a custom toolbar called Password, so users can change their password. I used the Command "User and Group Accounts". I know the user can not change anything in the Tab...
1
by: monkey1001 | last post by:
my program is suppose to show my due change and i got it working but my change and coins are wrong how can i improve it thank you..(its supposed to be in java)
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.