Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

split String not working in java can't import `split`

Tags:

java

string

split

I am trying to split a string as the code below

String []data = {"3.5,2.3,4.2,5.4,7.4,2.7"};
String s[] = data.split("\\,");

double point3[] = new Double [s.length];
double allPoint[] = new double [s.length];

for (int i = 0; i < s.length; i++){
   point3[2] = Double.parseDouble(s[2]);
   //lng[i] = Double.parseDouble(s[i]);
   allPoint[i] = Double.parseDouble(s[i]);
}

I also tried with data.split(","); But the problem is not with backslashes, it gives error at split and hint shows that

cannot find symbol, symbol: method split(String)

I'm unable to import split what can I do now.


1 Answers

The method split() belongs to String, not to Array. To make this work, you must define your data as String data = "3.5,2.3,4.2,5.4,7.4,2.7"; instead.

like image 63
ljleppan Avatar answered Sep 26 '26 10:09

ljleppan



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!