- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 2616 Articles for Java
463 Views
The java.util.regex package of java provides various classes to find particular patterns in character sequences. The pattern class of this package is a compiled representation of a regular expression.The matches() method of the Pattern class accepts −A string value representing the regular expression.An object of the CharSequence class representing the input string.On invocation, this method matches the input string against the regular expression. This method returns a boolean value which is true in-case of a match else, false.Exampleimport java.util.Scanner; import java.util.regex.Pattern; public class MatchesExample { public static void main(String[] args) { //Getting the date ... Read More
2K+ Views
The java.util.regex package of java provides various classes to find particular patterns in character sequences.The pattern class of this package is a compiled representation of a regular expression. The quote() method of this class accepts a string value and returns a pattern string that would match the given string i.e. to the given string additional metacharacters and escape sequences are added. Anyway, the meaning of the given string is not affected.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class QuoteExample { public static void main( String args[] ) { //Reading string value Scanner ... Read More
13K+ 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
113 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
120 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
128 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
229 Views
The subexpression/metacharacter “( )” groups the regular expressions and remembers the matched text.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main( String args[] ) { String input = "Hello how are you welcome to Tutorialspoint"; String regex = "H(ell|ow)"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); //Retrieving the matcher object Matcher matcher = pattern.matcher(input); if(matcher.find()) { System.out.println("Match found"); } else { ... Read More
155 Views
The subexpression/metacharacter “\B” matches the non-word boundaries.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main( String args[] ) { String regex = "\Bcause"; Scanner sc = new Scanner(System.in); System.out.println("Enter a string: "); String input = sc.nextLine(); Pattern p = Pattern.compile(regex); Matcher m = p.matcher(input); int count = 0; while(m.find()) { count ++; } System.out.println("Number of matches: "+count); } ... Read More
313 Views
The java.util.regex package of java provides various classes to find particular patterns in character sequences. The pattern class of this package is a compiled representation of a regular expression.To match a specific character from the given input string −Get the input string.This compile() method of this class accepts a string value representing a regular expression and an integer value representing a flag returns a Pattern object. Compile the regular expression bypassing −The pattern matcher “[ ]” with required character in it ex: “[t]”.The flag CASE_INSENSITIVE to ignore case.The matcher() method of the Pattern class accepts an input string and returns ... Read More
529 Views
The pattern class of the java.regex package is a compiled representation of a regular expression.The compile() method of this class accepts a string value representing a regular expression and returns a Pattern object.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CompileExample { public static void main( String args[] ) { //Reading string value Scanner sc = new Scanner(System.in); System.out.println("Enter input string"); String input = sc.nextLine(); //Regular expression to find digits String regex = "(\d)"; //Compiling the regular expression ... Read More