-
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
-
You should build a class Bundle:
Code:
public class Bundle {
private String name;
private double[] pipes= double[4];
private String remarks;
// constructor(s) go here ...
}
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.
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:
Code:
public void update(Bundle that) {
this.pipes[0]+= that.pipes[0];
}
You fill in the details ...
kind regards,
Jos
-
Wouldn't a HashSet make more sense, since there should only be one of each thing? Barring the ordering, of course, but you can always get round that.