[Solved] Java: How to fix ArrayIndexOutOfBoundsException? [closed]


You are out of array because in for you use i<=s.length but max index of array is s.length-1

But I am interested in this

String[] data = new String[(scn.nextLine()).length()];
data = (scn.nextLine()).split(",");

Why are you creating empty array and then replace it with new one?
I think you wanted to create something more like this

String[] data = scn.nextLine().split(",");

Earlier you ware creating array based on second line of user input because you ware invoking scn.nextLine() twice.

4

solved Java: How to fix ArrayIndexOutOfBoundsException? [closed]