-1

I'm trying to fill an array of 2 elements with a element from another array, split by "." but it doesn't fill (for instance, the input is "83.105" and i need the first element to be "83" and the second "105"). When i try to get the 0 element from numberParts array it shows out of bounds exception. I'm really confused since this method is working on C# but not Java.

String[] inputNumbers = console.nextLine().split(" ");

String[] numberParts = inputNumbers[0].split(".");
System.out.println(numberParts[0]);
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97

1 Answers1

3

Dot (.) is a char that must be escaped in the split method.

why? because is a reserved character in regex

if not, splitting will return an empty array

String myString = "83.105";
String[] x = myString.split("\\.");

System.out.println(x[0]);
System.out.println(x[1]);
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97