I'm trying to input values in ArrayList but they are restored from second index. Below is the essential code.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
String answers = null;
ArrayList<String> arr = new ArrayList<>();
for (int i = 0; i < n; i++) {
answers = scanner.nextLine();
arr.add(answers);
}
This is what I input.
5
OOXXOXXOOO
OOXXOOXXOO
OXOXOXOXOXOXOX
OOOOOOOOOO
OOOOXOOOOXOOOOX
I tried to check out the first value of arr("OOXXOXXOOO"), but nothing was printed. In addition, I tried to figure out the last value of arr("OOOOXOOOOXOOOOX"), but the second value from the end("OOOOOOOOOO") was printed. In my opinion, values might be put from the second place of ArrayList. What should I do to store whole strings into ArrayList without cutout happening?