Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

 

and many more ....

 

 

Determine if a string matches a pattern exactly

This is an example of how to determine if a String matches to a Pattern exactly. Using a Matcher to check if a String matches to a specified Pattern implies that you should: Compile a given String regular expression to a Pattern, using compile(string regex) API method of Pattern. The given regex in the example is the character “b”. Use ...

Read More »

Matcher.appendReplacement example – Part 2

In this example we shall show you how to use Matcher.appendReplacement(StringBuffer sb, String replacement) API method to append to a StringBuffer the result of a Matcher. To use a StringBuffer to append a Matcher’s result one should perform the following steps: Compile a given String regular expression to a Pattern, using compile(string regex) API method of Pattern. Use matcher(CharSequence input) ...

Read More »

Strip extra spaces in a string

With this example we are going to demonstrate how to strip extra spaces in a String. In short, to strip extra spaces in a String you should: Use a given String with spaces between words. Use replaceAll(String regex, String replacement) API method of String, with a given regular expression. The regular expression is constructed by the white character between the ...

Read More »

Simple positive Lookbehind

This is an example of a simple positive look behind. Positive look behind methods assert the existence of a pattern to the left of the position of a String. You can form positive look behinds by opening a noncapturing group with (?<=. Positive looking behind in a String implies that you should: Compile a given String regular expression to a ...

Read More »

Find occurances of a letter in a string

In this example we shall show you how to find occurances of a specific letter in a String. To find occurances of a letter in a String one should perform the following steps: Compile a given String regular expression to a Pattern, using compile(string regex) API method of Pattern. The given regex in the example is a word boundary followed ...

Read More »

Get all digits from a string

With this example we are going to demonstrate how to get all digits from a String, using a regular expression. In short, to get all digits from a String you should: Use a given String with letters and digits. Use replaceAll(String regex, String replacement) API method of String, with a given regular expression and a String to be used as ...

Read More »

Split a string by regular expression

This is an example of how to split a String using regular expression. Splitting a String with a regular expression implies that you should: Compile a given String regular expression to a Pattern, using compile(string regex) API method of Pattern. The given regular expression in the example is the String “ian”. Use split(CharSequence input) API method of Pattern to split ...

Read More »

Parse an Apache logfile with regular expressions

In this example we shall show you how to parse an Apache logfile with regular expressions. To parse an Apache logfile with regular expressions we have followed the steps below: We have created an interface with a static final int that is the number of fields to be found and a static final String that is the log entry to ...

Read More »

Word frequency count example

With this example we are going to demonstrate how to count the frequency of words in a file. In short, to count the frequency of words in a file you should: Create a new FileInputStream with a given String path by opening a connection to a file. Get the FileChannel object associated with the FileInputStream, with getChannel() API method of ...

Read More »

Split string example

This is an example of how to split a String. We will split a given String using the Pattern API. Splitting a given String implies that you should: Read the given input String. Compile a given String regular expression to a Pattern, using compile(string regex) API method of Pattern. The given regex in the example is the exclamation point. Use ...

Read More »