We moved our repositories to BitBucket!

If you can't login or you can't register to the forums do not rise an issue, instead please write to support (at) l2jserver.com

Check our wiki!

Report server issues here

Forum has been updated to phpBB 3.2, let's see if this fixes some minor bugs we had.

Thank you for visiting http://www.l2jserver.com/

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: 222
Joined: Sat Jul 26, 2014 5:58 pm
Location: ИРК, РФ, СИБИРЬ!
Contact:

Question with string :)

Post by KGB1st » Fri Nov 13, 2015 3:55 pm

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:
SPOILER:
Image
### GameServer: Started, free memory 1794 Mb of 3641 Mb
## -Xms2048m -Xmx4096m -XX:+AggressiveOpts
# GameServer: Server loaded in 51 seconds.

User avatar
LasTravel
Advanced User
Advanced User
Posts: 887
Joined: Tue Jan 05, 2010 12:08 am
Location: Spain

Re: Question with string :)

Post by LasTravel » Sat Nov 14, 2015 8:01 am

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

Code: Select all

String val = data[1];
Image

User avatar
KGB1st
Posts: 222
Joined: Sat Jul 26, 2014 5:58 pm
Location: ИРК, РФ, СИБИРЬ!
Contact:

Re: Question with string :)

Post by KGB1st » Sat Nov 14, 2015 9:13 am

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)?
SPOILER:
Image
### GameServer: Started, free memory 1794 Mb of 3641 Mb
## -Xms2048m -Xmx4096m -XX:+AggressiveOpts
# GameServer: Server loaded in 51 seconds.

User avatar
SaveGame
Posts: 121
Joined: Thu Oct 30, 2014 9:54 pm

Re: Question with string :)

Post by SaveGame » Sat Nov 14, 2015 10:25 am

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()

Post Reply