DinhNguyen
0
Q:

string replace java

public static void main(String args[]){  
String s1="my name is khan my name is java";  
String replaceString=s1.replace("is","was");//replaces all occurrences of "is" to "was"  
System.out.println(replaceString);  
}}  
6
String str = ".............................."; 

        int index = 5; 
  
        char ch = '|'; 
 
        StringBuilder string = new StringBuilder(str); 
        string.setCharAt(index, ch); 

        System.out.println(string); 
2
String s1 = "my name is khan and my name is java";
String replaceString = s1.replace("is","was");
//replaces all occurrences of "is" to "was"
System.out.println(replaceString);
0
String str = "helloslkhellodjladfjhello";
String findStr = "hello";
int lastIndex = 0;
int count = 0;
while(lastIndex != -1){
    lastIndex = str.indexOf(findStr,lastIndex);
    if(lastIndex != -1){
        count ++;
        lastIndex += findStr.length();
    }
}
System.out.println(count);
0

New to Communities?

Join the community