File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "ArrayList " Watch "ArrayList " New topic
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: ArrayList
 
Similar Threads
getting Class cast exception
What is the dfference between these two loops?
Generics Question
how to improve my program code ?
ArrayList of ArrayList<String>