Results 1 to 3 of 3
Thread: arraylist handling
- 07-18-2010, 08:23 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 1
- Rep Power
- 0
arraylist handling
here's what my code should do:
bundle01|1.0|2.0|3.0|4.0|remarks
bundle02|1.0|2.0|3.0|4.0|remarks
bundle03|1.0|2.0|3.0|4.0|remarks
bundle02|1.0|2.0|3.0|4.0|remarks
my array should only include no duplicate bundle.
so i want to exclude the one bundle02 in the list and its 2nd pipe delimited value ( 1.0 ) will be added to the 2nd pipe delimited.
output below:
duplicate remove form the list, 2nd pipe delimited sums up to 2.0
bundle01|1.0|2.0|3.0|4.0|remarks
bundle02|2.0|2.0|3.0|4.0|remarks
bundle03|1.0|2.0|3.0|4.0|remarks
try some code lines i only able to remove duplicate lines but unable to add the sum of the 2nd pipe delimited value.
appreciate much your response
thank you all
Edit/Delete Message
- 07-18-2010, 08:35 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
You should build a class Bundle:
That class should have a bit of algebra defined in it, i.e. it should implement an equals( ... ) method (and the hashCode() method that comes with it) so that you can put a Bundle in a HashMap. If you want a bit of ordering in your Bundles your class should also implement the Comparable<Bundle> interface.Java Code:public class Bundle { private String name; private double[] pipes= double[4]; private String remarks; // constructor(s) go here ... }
If a Bundle already occurs in your map the Bundle should be updated (the first pipe length? should be adjusted); it can be done with a simple method like this:
You fill in the details ...Java Code:public void update(Bundle that) { this.pipes[0]+= that.pipes[0]; }
kind regards,
Jos
- 07-19-2010, 10:25 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Event Handling
By zzpprk in forum AWT / SwingReplies: 2Last Post: 11-12-2009, 09:30 PM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks