So currently, I have an ArrayList that looks something like:
[ [id, type, name, $], [id, type, name, $], [id, type, name, $], [id, type, name, $]....]
Now say if i want to compare index 0 with 1, or maybe I want to add another value after the comma:
[id, type, name, $, YOLO]
How would I go about doing this? thanks!
Edit: here something:
I am reading data from Excel:
for (int i = first; i <= last; i++) {
Row row = sheet.getRow(i);
Cell id = row.getCell(0);
Cell type = row.getCell(1);
Cell name = row.getCell(2);
Cell $ = row.getCell(3);
List temp = new ArrayList();
temp.add(id);
temp.add(type);
temp.add(name);
temp.add($);
sData.add(temp);
}
and then when you print sData, it shows exactly how I said earlier.
An ArrayList in Java is a dynamic structure to hold a collection of objects.
In your case I suspect that you have an Object with attributes id, type, name and $ and you store them in the ArrayList using .add(Object) method.
What you want is to add another attribute to your Object and use the same method to add that Object to your ArrayList.
The thing you say about comparing the index…. (i suppose you mean the id variable of each object). Well that is also easy (suppose you implement the apropriate methods in your object – lets say for the variable id you should have a method setId and getId … etc):
UPDATE
And this is the manipulation of the Object