Home Tutorial Java Core Find Successively Repeated Character using Java

 
 

Find Successively Repeated Character using Java
Posted on: October 24, 2009 at 12:00 AM
In this section, we are going to find the successively repeated character using Regular Expression.

Find Successively Repeated Character using Java

In this section, we are going to find the successively repeated character using Regular Expression. For this, we have specified a word 'programming' and with use of Pattern and Matcher class, we have found that 'm' is repeated successively.

Here is the code of Main_Class.java

import java.util.regex.*;

public class Main_Class{
public static void main(String[] args){
String st = "programming";
Pattern p = Pattern.compile("(\\w)\\1+");
Matcher m = p.matcher(st);
if (m.find()){
System.out.println("Repeated character is " + m.group(1));
}
}
}

Output:

Repeated Character is m

Related Tags for Find Successively Repeated Character using Java:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.