• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

comparing and sorting arraylist of arraylist

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
dav mrazek
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic