(New string split method) The split method in the Stringclass returns an array o
ID: 3610195 • Letter: #
Question
(New string split method) The split method in the Stringclass returns an array of strings consisting of the substringssplit by the delimiters. However, the delimiters are not returned.Implement the following new method that returns an array of stringsconsisting of the substrings split by the matches, including thematches.public static String[] split(String s, Stringregex)
For example, split("ab#12#453", "#")returns ab, #,12, #,453 in an array of String, and split("a?b?gf#e","[?#]") returns a, b, ?, b, gf, #, and e in an array ofString.
Explanation / Answer
please rate - thanks I believe your sample is wrong split("a?b?gf#e", "[?#]") returnsa, b,?, b,gf, #, ande it's missing the ? between the a and b try this--the previous answer doesn't even have a methoddefined public class JavaStringSplit { public static void main(String args[]) { String[]temp; String str="a?b?gf#e", delimiters="[?#]"; temp = split(str, delimiters); System.out.println("The strings in "+str+" alongwith the delimeters "+delimiters+" are:"); for(int i =0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.