ArrayList<Integer> bigger = new ArrayList<>();
for (int x = 0; x < numbers.size(); x++) {
int current = numbers.get(x);
ArrayList<Integer> temp = new ArrayList<>();
temp.add(current);
for (int y = x + 1; y < numbers.size(); y++) {
int nextValue = numbers.get(y);
if (nextValue == current + 1) {
temp.add(nextValue);
current = nextValue;
}
else {
break;
}
}
if (temp.size() > bigger.size()) {
bigger.clear();
bigger.addAll(temp);
}
}
numbers
is the ArraList of your numbers and
Inside bigger
is your sequence.
1
solved Find longest squential streak in arraylist java [closed]