Method Description: Remove all the str1 str2 and returns the result of deletion, return result Object [] array

/ ** 
* define a method
* public Object [] deleteSubString (str1 String, String str2) {
*
*}
* Method Description: Remove all the str1 str2 and returns the result of deletion, return the result of object [] array
* the first element of the array is the final string remove all str2
* the second element of the array is the number of deleted str2
*
* /
public class Test06 {
public static void main (string [] args ) {
String S1 = "aabbccaaddssddaaeewwdd";
String S2 = "AA";
Object [] = deleteSubString Objects (S1, S2);
System.out.println (of Arrays.toString (Objects));

}

/ **
* the array the final element of the first string to delete all str2
* the second element of the array is the number of deleted str2
* @param str1
* @param str2
* @return
*/
public static Object[] deleteSubString(String str1,String str2){
Object[] arr = new Object[2];
int sum = 0;
while(str1.contains(str2)){
str1 = str1.replaceFirst(str2,"");
sum++;
}
arr[0] = str1;
arr[1] = sum;
return arr;
}
}

Guess you like

Origin www.cnblogs.com/YRSWBY2016/p/12015842.html