1public static void main(String args[]){
2String s1="my name is khan my name is java";
3String replaceString=s1.replace("is","was");//replaces all occurrences of "is" to "was"
4System.out.println(replaceString);
5}}
6
1String str = "..............................";
2
3 int index = 5;
4
5 char ch = '|';
6
7 StringBuilder string = new StringBuilder(str);
8 string.setCharAt(index, ch);
9
10 System.out.println(string);
1String s1 = "my name is khan and my name is java";
2String replaceString = s1.replace("is","was");
3//replaces all occurrences of "is" to "was"
4System.out.println(replaceString);
1public static void main(String args[]){
2String s1="my name is khan my name is java";
3String replaceString=s1.replace("is","was");//replaces all occurrences of "is" to "was"
4System.out.println(replaceString);
5}}
1String str = "helloslkhellodjladfjhello";
2String findStr = "hello";
3int lastIndex = 0;
4int count = 0;
5while(lastIndex != -1){
6 lastIndex = str.indexOf(findStr,lastIndex);
7 if(lastIndex != -1){
8 count ++;
9 lastIndex += findStr.length();
10 }
11}
12System.out.println(count);