This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes comparing and sorting arraylist of arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "comparing and sorting arraylist of arraylist" Watch "comparing and sorting arraylist of arraylist" New topic
Author

comparing and sorting arraylist of arraylist

dav mrazek
Ranch Hand

Joined: Aug 11, 2007
Posts: 69
Hello i would like some help for my problem. Here is an exemple of the arraylist of arraylist i have got :


My problem is that, from this arrayList, i have to compare the string element of each list to see if they are equals. Then if they are equals, i have to add the integer of each column with equal string between them and finally remove one of the duplicate array, so for the exemple the result would be :
dav mrazek
Ranch Hand

Joined: Aug 11, 2007
Posts: 69
I dont know if my algorithm is good but i manage to have an array of array containing the doubled data :


Now i would like some help for adding column together then merge the array with my original ArrayList of ArrayList.

Thank you for any help
Subhash Bhushan C
Ranch Hand

Joined: Jan 27, 2005
Posts: 106
Solved your problem with a combination of ArrayList and Map. In fact, I used Arraylist just to illustrate to you. You can very well skip ArrayList completely, and use Map along with your class.

You can read up on Collections here: Trail: Collections (The Java Tutorial)

Here is the class containing your data:


And here is a small implementation to show how the adding is done:


And this is the output I get:

----------------------
ArrayList Data
----------------------
FIRST-1-0-2-0-3-0-4-0
SECOND-3-0-4-0-5-0-6-0
FIRST-5-0-6-0-7-0-8-0
----------------------


----------------------
Map Data
----------------------
SECOND-3-0-4-0-5-0-6-0
FIRST-6-0-8-0-10-0-12-0
----------------------


[ April 22, 2008: Message edited by: Subhash Bhushan ]

Regards,<br />Subhash Bhushan.
dav mrazek
Ranch Hand

Joined: Aug 11, 2007
Posts: 69
Thanks greatly for this, it will help me a lot. Pity i m not using java 5 but still 1.4.2, but i didnt think about working with map which seems to be very convenient in this case, thanks, ill try work through your exemple and adapt it to my case.
 
Consider Paul's rocket mass heater.
 
subject: comparing and sorting arraylist of arraylist