Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - converting String in array to double

Tags:

java

arrays

I'm stuck with this pretty silly thing;

I got a textfile like this;

Hello::140.0::Bye

I split it into a string array using;

LS = line.split("::");

Then I try to convert the array values containing the number to a double, like this;

Double number = Double.parseDouble(LS[1]);

But I get the following error message;

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1

Does anyone have any idea why this doesn't work?

like image 244
cc0 Avatar asked Mar 22 '26 03:03

cc0


1 Answers

I think it's a problem with reading the file. Did you try printing line and also the contents of LS after splitting?

like image 109
Halo Avatar answered Mar 24 '26 18:03

Halo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!