How about using StringUtils.countMatches from Apache Commons Lang?
String str = "helloslkhellodjladfjhello";
String findStr = "hello";
System.out.println(StringUtils.countMatches(str, findStr));
That outputs:
3
More Related Contents:
- incompatible types required char found java.lang.string
- How to enter quotes in a Java string?
- String, StringBuffer, and StringBuilder
- Problems converting byte array to string and back to byte array
- String concatenation: concat() vs “+” operator
- Parse String to Date with Different Format in Java
- Convert character to ASCII numeric value in java
- Strip Leading and Trailing Spaces From Java String
- How can I use “.” as the delimiter with String.split() in java [duplicate]
- How to replace case-insensitive literal substrings in Java
- How to use regex in String.contains() method in Java
- How to check that a string is parseable to a double? [duplicate]
- How to convert current date into string in java?
- Reverse a given sentence in Java
- How do I escape a string in Java?
- How to convert a String into an ArrayList?
- Remove end of line characters from Java string
- String Deduplication feature of Java 8
- Convert String to Uri
- Calculating frequency of each word in a sentence in java
- Remove all non-“word characters” from a String in Java, leaving accented characters?
- Fastest way to strip all non-printable characters from a Java String
- Simple way to sort strings in the (case sensitive) alphabetical order
- What’s the best way to check if a String contains a URL in Java/Android?
- What’s the quickest way to compare strings in Java?
- Replace Last Occurrence of a character in a string [duplicate]
- What is a Java String’s default initial value?
- Hints for java.lang.String.replace problem? [duplicate]
- How to convert a Java String to an ASCII byte array?
- What is difference between mutable and immutable String in java