What is split in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is split in java?

Can anyone explains me this?

14th Jul 2020, 8:34 AM
@Danish🇦🇫
@Danish🇦🇫 - avatar
4 Answers
+ 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?"}
14th Jul 2020, 9:01 AM
Imagine Time
Imagine Time - avatar
14th Jul 2020, 8:51 AM
Ayush Kumar
Ayush Kumar - avatar
+ 3
I have specified it telling split based on a particular character specified Please read it again
14th Jul 2020, 2:02 PM
Imagine Time
Imagine Time - avatar
+ 1
Split() is used to split a sentence around anything be it at space ,a specific character or anything else.
14th Jul 2020, 1:58 PM
shubham kumar
shubham kumar - avatar