
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

361 Views
The java.util.regex.Matcher class represents an engine that performs various match operations. There is no constructor for this class, you can create/obtain an object of this class using the matches() method of the class java.util.regex.Pattern.The pattern() method of this (Matcher) class fetches and returns a Pattern (object) interpreted by the current Matcher.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class PatternExample { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter your date of birth (MM/DD/YYY)"); String date = sc.next(); String regex = "^(1[0-2]|0[1-9])/(3[01]|[12][0-9]|0[1-9])/[0-9]{4}$"; ... Read More

313 Views
The Predicate interface of the java.util.function package can be used as a target for lambda expressions. The test method of this interface accepts a value ad validates it with the current value of the Predicate object. This method returns true in-case of a match, else false.The asPredicate() method of the java.util.regex.Pattern class returns a Predicate object which can match a string with the regular expression using which the current Pattern object was compiled.Example 1import java.util.Scanner; import java.util.function.Predicate; import java.util.regex.Pattern; public class AsPredicateExample { public static void main( String args[] ) { //Reading string value ... Read More

684 Views
Enables the Unicode version of Predefined character classes and POSIX character classes. Example import java.util.regex.Matcher; import java.util.regex.Pattern; public class UNICODE_CHARACTER_CLASS_Example { public static void main( String args[] ) { String regex = "\u00de"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CHARACTER_CLASS); //Retrieving the matcher object String str[] = {"\u00de", "\u00fe", "\u00ee", "\u00ce"}; for (String ele : str) { Matcher matcher = pattern.matcher(ele); ... Read More

297 Views
This flag enables Unix lines mode. In the Unix lines mode, only '' is used as a line terminator and ‘\r’ is treated as a literal character. Example 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class LTERAL_Example { public static void main(String[] args) { String input = "This is the first line\r" + "This is the second line\r" + "This is the third line\r"; //Regular expression to accept ... Read More

1K+ Views
Enables Unicode-aware case folding. When you use this as flag value to the compile() method along with the CASE_INSENSITIVE flag and if you search for Unicode characters using regular expressions Unicode characters of both cases will be matched. Example import java.util.regex.Matcher; import java.util.regex.Pattern; public class UNICODE_CASE_Example { public static void main( String args[] ) { String regex = "\u00de"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CASE|Pattern.CASE_INSENSITIVE); //Retrieving the matcher object String str[] = {"\u00de", "\u00fe", ... Read More

3K+ Views
Enables multiline mode in general, the ^ and $ meta characters matches the start and end of the given input with the specified characters irrespective of the number of lines in it. Example 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class MULTILINE_Example { public static void main( String args[] ) { //String regex = "(^This)";//.*t$)"; String input = "2234 This is a sample text" + "1424 This second 2335 line" + "This id third 455 line" ... Read More

18K+ Views
A JsonNode is a base class for all JSON nodes that forms the JSON Tree Model whereas ArrayNode is a node class that represents an array mapped from JSON content. We can convert or translate JsonNode to ArrayNode by typecasting the ArrayNode to retrieve the values using the readTree() method of ObjectMapper class and get() method for accessing the value of a specified element of an array node.Syntaxpublic JsonNode readTree(String content) throws IOException, com.fasterxml.jackson.core.JsonProcessingExceptionExampleimport com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.core.JsonProcessingException; public class JSonNodeToArrayNodeTest { public static void main(String args[]) throws JsonProcessingException { String jsonStr = "{\"Technologies\" : [\"Java\", ... Read More

182 Views
The subexpression/metacharacter “re?” matches 0 or 1 occurrence of the preceding expression.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main( String args[] ) { String regex = "Wel?"; String input = "Welcome to Tutorialspoint"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(input); int count = 0; while(m.find()) { count++; } System.out.println("Number of matches: "+count); } }OutputNumber of matches: 1Example 2Following Java program accepts a string from ... Read More

173 Views
The subexpression/metacharacter “(?> re)” matches the independent pattern without backtracking.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class PatternExample { public static void main(String args[]) { //Reading String from user System.out.println("Enter a String"); Scanner sc = new Scanner(System.in); String input = sc.next(); String regex = "(?>[0-9])"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); //verifying whether match occurred boolean ... Read More

188 Views
The subexpression/metacharacter “(?: re)” groups regular expressions without remembering the matched text.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class PatternExample { public static void main(String args[]) { //Reading String from user System.out.println("Enter a String"); Scanner sc = new Scanner(System.in); String input = sc.next(); String regex = "(?:[0-9])"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); //verifying whether match occurred ... Read More