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
Advertisement
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
Advertisement

Related Tags for Find Successively Repeated Character using Java:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 24, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com