Learn Java Programming - String Class split(...)

preview_player
Показать описание
The split() method is a very useful tool for parsing strings. In the signature above, the first parameter is named regex and that is significant; regex is an abbreviation for regular expression and you will hear the term regex used quite often. Regular expressions deserve an entire mini-tutorial series on their own, so I will just use a basic regex parameter for this tutorial. The split() method is overloaded and has two different signatures. The split(String regex) returns an array of strings that are separated by a delimiter. For example,
String s = "Apple-Banana-Orange-Pear-Watermelon";
for(String temp :fruits ) {
}

The split(String regex, int limit) returns an array of strings that are separated by a delimiter, the second parameter specifies the max number of elements in the array. This method will most likely not work as you might expect, the last element of the array will contain all the rest of the entire string. For example,
String s = "Apple-Banana-Orange-Pear-Watermelon";
for(String temp : fruits ) {
}
Рекомендации по теме
Комментарии
Автор

Thank you sir, i didnt knew this function was so usefull until now

ivanyovev
Автор

This was very helpful! I was stuck on a homework where I had to take an String that was reverse and then put it on a new array of 5 elements. You just answered the doubt I've been having for the last 2 days!!! You are awesome!

dentistde
Автор

This is very helpful, thanks a lot! now I got it

Termnusst
Автор

Danke für das Video es hat mir sehr geholfen, Thank you for this Video it helfen mehr so.

devfritze
Автор

sir after splitting i want to search the specific Word from my Sql server Database and want to get anything i've stored regarding that string in my database... what should i do????

parveshkumar