Thursday, December 27, 2012

Increment certain values in an ArrayList.

I needed to add 1 to certain values in an ArrayList and this was the only way I could figure it out easily.
ArrayList<Integer> q3=new ArrayList<Integer>();
q3.add(4); /// Populate the arraylist
q3.add(6);
q3.add(10);
q3.set(1,((q3.get(1)+1))); ///adds 1 to the current location
view raw gistfile1.txt hosted with ❤ by GitHub

It is basically calling to set q3 at location 1 with the former q3 value +1.  IN this case 6+1=7;

No comments:

Post a Comment