I am trying to get input in collections using for loop but somehow output displays 0th position empty
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
ArrayList<String> b = new ArrayList<String>();
String abc;
for (int i = a; i > 0; i--) {
abc = sc.nextLine();
b.add(abc);
}
I expect output to be:
[a, d, b, c, e]
but actual output is:
[, a, d, b, c]