+ 1
What is split in java?
Can anyone explains me this?
4 Antworten
+ 6
What split does is
If you have a string
Ex - String s = "Hello How are you?"
And you use the split method on it like
String[] array = s.split(" ");
This method will return an array which will have strings which are different words of the string.
Which are separated by space.
The value of array
Will be
{ "Hello", "How","are","you?" }
You can give any character to split method and it will split the given string based on the occurrences the a paricular character. It can also have an additional parameter
Which will be an integer value
This will return the no. Of strings array words based on the no. Of values;
Ex- String s = "Hello How are you?";
String[] arr = s.split(" ", 2);
Due to this the value of arr will be
{ "Hello" ,"How are you?"}
+ 3
+ 3
I have specified it telling split based on a particular character specified
Please read it again
+ 1
Split() is used to split a sentence around anything be it at space ,a specific character or anything else.