Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to count an replace substring string in java

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);
Comment

how to count an replace string in java

public static void main(String[] args) throws Exception {
        String word = "abcdefg";
        System.out.println(word.length());
        System.out.println(word.replace("a", "").length());
        int a_counter = word.length() - word.replace("a", "").length();
        System.out.println(a_counter);
}
Comment

PREVIOUS NEXT
Code Example
Java :: Simple java questionnaire using json 
Java :: ERROR: Failed to resolve: com.github.HaarigerHarald:android-youtubeExtractor:v1.7.0 
Java :: Java @Retention 
Java :: change from one java compiler to another in cmd 
Java :: turn on device location android programmatically 
Java :: run app by package android 
Java :: 710*12 
Java :: java oop design patterns 
Java :: java scan next into array 
Java :: Filter out any non-printable characters 
Java :: change focus of edittext android when click outside 
Java :: interviewbit_java 
Java :: list to vector java 
Java :: java Sum of all the factors of a number 
Java :: Java Using Looping Construct to Copy Arrays 
Java :: is type java 
Java :: java find view by id 
Java :: what does put extra do? 
Java :: Java Insert Elements to LinkedHashSet 
Java :: como detener un void java 
Java :: heap vs string constant pool 
Java :: hierarchy inheritance gfg java 
Java :: multiple recyclerview not scrolling bottom sheet 
Java :: ein wort in buchstaben zerlegen java 
Java :: editable column 
Java :: staging and production environment logging spring boot 
Java :: how to romve a element from arraylist in java 
Java :: java int data type 
Java :: stop countdown timer when exiting an activity 
Java :: webmvctest vs springboottest 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =