Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Match all occurrences of a regex in Java
public class RegexOccur {
public static void main(String args[]) {
String str = "java is fun so learn java";
String findStr = "java";
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);
}
}
Output
2
Advertisements