I'm confused as to how that line works. Wouldn't the list.remove delete the first string and then make it impossible to move that string to the end?
Shouldn't it be " list.remove(list.add(0)); " instead?
package com.codegym.task.task07.task0720;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Shuffled just in time
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(reader.readLine());
int M = Integer.parseInt(reader.readLine());
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < N; i++) {
String text = reader.readLine();
list.add(text);
}
for (int i = 0; i < M; i++) {
list.add(list.remove(0));
}
for (String s : list) {
System.out.println(s);
}
}
}