replace sub string. This method accepts three references to String objects as arguments. Let's call them string1, string2, and string3. It searches string1 for all occurrences of string2. When it finds an occurrence of string2, it replaces it with string3. For example, suppose the three arguments have the following values that would return a reference to a String object with the value "that dog jumped over that fence":
string1: "the dog jumped over the fence"
arrayToString Convert array to string
Demonstrate each of these methods in a complete program.
Breaking it down
StringTokenizer uses the space character, the tab character, the newline character, the carriage-return character, and the form-feed character (" \t\n\r\f") as a set of predefined delimiters to split a string. countTokens() will return the number of tokens remaining in the current delimiter set which results in the number of words in a string. One thing to note is that the delimiters themselves will not be treated as tokens.
Once the string is grouped and counted we will order the hashmap by value in descending order. This will have the highest to lowest value and to get the most frequent we will get the first entry.
Replace a string within string
To replace a string within a string, there is three parameters that need to be passed. First, the original string, second the string to find and finally the value to replace it with. The comments in the code will walk through additional logic.