Maruthi Krishna has Published 951 Articles

Accepting date strings (MM-dd-yyyy format) using Java regex?

Maruthi Krishna

Maruthi Krishna

Updated on 21-Feb-2020 10:39:39

3K+ Views

The following is the regular expression to match the date in the dd-MM-yyyy format.^(1[0-2]|0[1-9])/(3[01]|[12][0-9]|0[1-9])/[0-9]{4}$To match a date in a string in that format.Compile the above expression of the compile() method of the Pattern class.Get the Matcher object bypassing the required input string as a parameter to the matcher() method of ... Read More

Custom UnaryOperator implementation in java.

Maruthi Krishna

Maruthi Krishna

Updated on 20-Feb-2020 12:04:09

306 Views

The java.util.function.UnaryOperator interface and can be used as assignment target for lambda expressions, it represents operation on a single operand whose result will be of same type as the input. We can create our own UnaryOperator by implementing this interface.The replaceAll() method of the List interface accept an object of ... Read More

How to remove an element from ArrayList or, LinkedList in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 17-Feb-2020 07:04:08

614 Views

The ArrayList and, LinkedList classes implements the List interface of the java.util package. This interface provided two variants of the remove() method to remove particular elements as shown below −E remove(int index)boolean remove(Object o) −Using one of these methods you can delete a desired element from the List or, linkedList ... Read More

What are wildcards arguments in Generics In Java?

Maruthi Krishna

Maruthi Krishna

Updated on 21-Jan-2020 12:16:39

1K+ Views

Generics is a concept in Java where you can enable a class, interface and, method, accept all (reference) types as parameters. In other words it is the concept which enables the users to choose the reference type that a method, constructor of a class accepts, dynamically. By defining a class ... Read More

Character class: union - Java regular expressions

Maruthi Krishna

Maruthi Krishna

Updated on 13-Jan-2020 06:52:15

460 Views

The character classes in Java regular expression is defined using the square brackets "[ ]", this subexpression matches a single character from the specified or, set of possible characters. For example the regular expression [abc] matches a single character a or, b or, c.The union variant of the character class ... Read More

Character class: range - Java regular expressions

Maruthi Krishna

Maruthi Krishna

Updated on 13-Jan-2020 06:49:55

93 Views

The character classes in Java regular expression is defined using the square brackets "[ ]", this subexpression matches a single character from the specified or, set of possible characters. For example, the regular expression [abc] matches a single character a or, b or, c.The range variant of the character class ... Read More

Character class: Negation - Java regular expressions

Maruthi Krishna

Maruthi Krishna

Updated on 13-Jan-2020 06:47:11

3K+ Views

The character classes in Java regular expression is defined using the square brackets "[ ]", this subexpression matches a single character from the specified or, set of possible characters.For example the regular expression [abc] matches a single character a or, b or, c. Similarly, "[a-z]" matches a single character from ... Read More

Matching multiple lines in Java regular expressions

Maruthi Krishna

Maruthi Krishna

Updated on 13-Jan-2020 06:44:13

699 Views

To match/search a input data with multiple lines −Get the input string.Split it into an array of tokens by passing "\r?" as parameter to the split method.Compile the required regular expression using the compile() method of the pattern class.Retrieve the matcher object using the matcher() method.In the for loop find ... Read More

Splitting the text using java.util.regex package

Maruthi Krishna

Maruthi Krishna

Updated on 13-Jan-2020 06:40:53

91 Views

The split() method of the String class accepts a regular expression, splits the current input text into tokens and returns them as a string array.Example Live Demoimport java.util.Scanner; public class Example{    public static void main(String[] args) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter input ... Read More

Named captured groups Java regular expressions

Maruthi Krishna

Maruthi Krishna

Updated on 13-Jan-2020 06:36:49

2K+ Views

Named capturing groups allows you to reference the groups by names. Java started supporting captured groups since SE7.Example Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ReplaceAll{    public static void main(String[] args) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter input text: ");   ... Read More

Advertisements