Sample String Code using Pattern and Matcher

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**

* @author asharda
*
*/
public class StringTest {

public static void main(String[] args) {

test();
test1();
}

public static void test() {
StringBuffer sb = new StringBuffer(“Hello”);
sb.setCharAt(1, ‘i’);
sb.setLength(2);
System.out.println(“New string now is ” + sb);
StringBuilder sb1 = new StringBuilder(“Hello”);
sb1.reverse();
System.out.println(“New string now is ” + sb1);

}

public static void test1() {
Pattern p = Pattern.compile(“Java”);
Matcher m = p.matcher(“Java”);
boolean found = m.matches();
if (found)
System.out.println(“Found”);
else
System.out.println(“Not Found”);
}
}

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s