Question with string :)

If something doesn't fit in any other forum then post it here.
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
KGB1st
Posts: 230
Joined: Sat Jul 26, 2014 5:58 pm

Question with string :)

Post by KGB1st »

Code: Select all

String[] data = event.split(" ");
String[] val = data[1];
Why in 1st code data sets to the string value, but in 2nd method I got ex about that it can't convert? :really:
User avatar
LasTravel
Posts: 888
Joined: Tue Jan 05, 2010 12:08 am
Location: Spain

Re: Question with string :)

Post by LasTravel »

Because data[1] is a String, not a String[], so you should use:

Code: Select all

String val = data[1];
User avatar
KGB1st
Posts: 230
Joined: Sat Jul 26, 2014 5:58 pm

Re: Question with string :)

Post by KGB1st »

LasTravel wrote:Because data[1] is a String, not a String[], so you should use:

Code: Select all

String val = data[1];
aaa.. this's such as dynmic sting (array)?
SaveGame
Posts: 121
Joined: Thu Oct 30, 2014 9:54 pm

Re: Question with string :)

Post by SaveGame »

Java is strictly typed. String#split(String) returns String[], which is a simple array.
A String in Java is not an array (although in typical JDK implementations there is a cached char[] underneath).

Consider

Code: Select all

char[] val = data[1].toCharArray()
Image
Post Reply