Solution{
String question
String answer
public Solution(String question,String answer){
...
}
}
List<Solution> solutions = new ArrayList<>();
Arrays.asList(
new Solution("Index1","a"),
new Solution("Index2","b"),
new Solution("Index3","c"),
new Solution("Index4","d"),
new Solution("Index5","ae"),
new Solution("Index1","afg"),
new Solution("Index2","adfg"),
new Solution("Index1","ag"),
new Solution("Index2","a"),
new Solution("Index3","a"),
new Solution("Index4","a"),
new Solution("Index5","a"),
new Solution("Index1","arrr"),
new Solution("Index2","a"),
new Solution("Index3","a"));
I always want to get last two sets starting from Index1 which are
new Solution("Index1","ag"),
new Solution("Index2","a"),
new Solution("Index3","a"),
new Solution("Index4","a"),
new Solution("Index5","a"),
new Solution("Index1","arrr"),
new Solution("Index2","a"),
new Solution("Index3","a"))
but I am not sure what is the best way to do that. I can think of reversing the list and then have a counter on Index1 which starts with 0 then do while loop to add it in a list until counter reaches 2. Not sure if this is possible with streams.