| Author |
ArrayList
|
venu jayaram
Greenhorn
Joined: Mar 11, 2008
Posts: 27
|
|
hi,
I am having the Arraylist it is having the values(10,11,12,14,15,16) it's series of element but 13 is missing if that arraylist is not in series i need to quit. this is working fine but the first index of the arraylist is not coming. i.e 10 always it's coming 11. in my logic please correct me that logic i should have the output [10,11,12].
please help me to solve this problem
......................
public class Test {
public static void main(String[] args) {
ArrayList<Integer> arr = new ArrayList();
arr.add(10);
arr.add(11);
arr.add(12);
arr.add(14);
arr.add(15);
arr.add(16);
int lastvalue = 0;
int currentvalue;
ArrayList<Integer> container = new ArrayList();
for (int rr : arr) {
currentvalue = rr;
if (lastvalue != 0) {
if (currentvalue - lastvalue == 1) {
container.add(rr);
// System.out.println(container.toString());
}else {
System.out.println(container.toString());
}
}
lastvalue = currentvalue;
}
}
}
thanks and regards
Venu J
|
 |
Eric Chang
Ranch Hand
Joined: Jan 27, 2004
Posts: 113
|
|
|
Just from a quick look, you appear to want to add lastValue to the container when you set lastValue to currentValue. container never contains the very first value (ie: 10) because you never add it.
|
 |
 |
|
|
subject: ArrayList
|
|
|