Answer the question
In order to leave comments, you need to log in
How to select the next element of a Java Collection object?
Good day! How to get the next element of a collection? There is a collection of objects, the object has two fields name and code (respectively, the get and set methods for them), the names need to be compared with each other, this is the responsibility of the method that takes two lines (the line and the line following it)
List<SomeClass> list = new ArrayList<SomeClass>();
for (SomeClass str : list) {
\\Строку я могу получить, но как получить следующую за ней строку?
someMethod(str.getName(), /*?????*/);
}
Answer the question
In order to leave comments, you need to log in
In this case, you need to use a regular loop, not a for-each loop
for(int i=0; i < list.size()-1; i++){
someMethod(list.get(i), list.get(i+1));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question