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

 

 

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 »

Simple string tokenizer

In this example we shall show you how to use a simple StringTokenizer. The string tokenizer class allows an application to break a string into tokens. To use a StringTokenizer one should perform the following steps: Construct a new StringTokenizer for a specified String. Use hasMoreElements() and nextToken() API methods of StringTokenizer to get the tokens from the string tokenizer. ...

Read More »

Parse a string to paragraphs

With this example we are going to demonstrate how to parse a String to paragraphs. In short, to parse a String to paragraphs you should: Compile a given String regular expression to a Pattern with given flag set to multiline mode, using compile(string regex, int flags) API method of Pattern. Use split(CharSequence input) API method of Pattern to split the ...

Read More »

Filter the content of a file using regular expressions

This is an example of how to filter the content of a file using regular expressions. Filtering the content of a file using regular expressions implies that you should: Compile a given String regular expression to a Pattern, using compile(string regex) API method of Pattern. Create a new FileInputStream with a given String path by opening a connection to a ...

Read More »

Filter lines from reader example

In this example we shall show you how to filter lines from a Reader. To filter lines from a Reader one should perform the following steps: Create a new BufferedReader that uses a FileReader with a given name of a file to read from. Compile a given String regular expression to a Pattern, using compile(string regex) API method of Pattern. ...

Read More »

Line ending matching example

With this example we are going to demonstrate how to check a line ending matching. We are using Patterns and Matchers against each pattern. In short, to check a line ending matching you should: Create a String array that contains the patterns to be used. For every pattern in the array compile it to a Pattern, using compile(string regex) API ...

Read More »