Found 2616 Articles for Java

How to search a value inside a JSON file using Jackson in Java?

raja
Updated on 09-Jul-2020 07:52:12

3K+ Views

The com.fasterxml.jackson.databind.node.ObjectNode class can be used to map the JSON object structure in Json content. We can search for a particular value inside the JSON file using the get() method of ObjectNode class, this method used for accessing the value of a specified field of an object node.Syntaxpublic JsonNode get(String fieldName)Exampleimport com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; public class ObjectNodeTest {    public static void main(String args[]) throws Exception {       String jsonString = "{\"Id\":101, \"name\":\"Raja Ramesh\", \"address\":\"Madhapur\"}";       ObjectMapper mapper = new ObjectMapper();       ObjectNode node = mapper.readValue(jsonString, ObjectNode.class);       if(node.has("name")) {       ... Read More

Matcher matches() method in Java with Examples

Maruthi Krishna
Updated on 19-Nov-2019 08:15:10

371 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 matches() method of this class matches the string with, the pattern represented by the regular expression (both given while creating this object). In the case of a match, this method returns true else it returns false. For the result of this method to be true, the entire region should have a match.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatchesExample {    public static void main(String ... Read More

Matcher find() method in Java with Example

Maruthi Krishna
Updated on 19-Nov-2019 08:13:12

657 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 find() method of this class tries to find the next subsequent input matching the current Matcher object, in case of the match this method returns true else it returns false.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class FindExample {    public static void main( String args[] ) {       //Reading string value       Scanner sc = new Scanner(System.in);       System.out.println("Enter ... Read More

Matcher end() method in Java with Example

Maruthi Krishna
Updated on 19-Nov-2019 08:11:54

188 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 end() method of the Matcher class returns the offset after the last match represented by the current object.The subexpression "[...]" matches the characters specified within the braces in the input string, In the following example using this to match the character t. Here, We have compiled the regular expression using the compile() method.Obtained the Matcher object.Invoked the matcher() method on each match.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import ... Read More

Matcher start() method in Java with Examples

Maruthi Krishna
Updated on 19-Nov-2019 08:09:44

222 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 start() method of the Matcher class returns the starting index of the matched character.ExampleThe subexpression "[...]" matches the characters specified within the braces in the input string, In the following example using this to match the character t. Here, We have compiled the regular expression using the compile() method.Obtained the Matcher object.Invoked the matcher() method on each match.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class StartExample ... Read More

How to match non-word boundaries using Java RegEx?

Maruthi Krishna
Updated on 19-Nov-2019 08:07:46

236 Views

You can match the non-word boundaries using the meta character “\B”.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example {    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.nextLine();       String regex = "\B";       //Compiling the regular expression       Pattern pattern = Pattern.compile(regex);       //Retrieving the matcher object       Matcher matcher = pattern.matcher(input);       int count = 0;     ... Read More

How to match word boundaries using Java RegEx?

Maruthi Krishna
Updated on 19-Nov-2019 08:06:01

316 Views

You can match the word boundaries using the meta character “\b”.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example {    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.nextLine();       String regex = "\b";       //Compiling the regular expression       Pattern pattern = Pattern.compile(regex);       //Retrieving the matcher object       Matcher matcher = pattern.matcher(input);       int count = 0;     ... Read More

How to match end of the input using Java RegEx?

Maruthi Krishna
Updated on 19-Nov-2019 08:04:07

424 Views

You can match the end of the input using the meta character “\z”.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example {    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.nextLine();       String regex = "[0-9]\z";       //Compiling the regular expression       Pattern pattern = Pattern.compile(regex);       //Retrieving the matcher object       Matcher matcher = pattern.matcher(input);       int count = 0;   ... Read More

How to match non-digits using Java Regular Expression (RegEx)

Maruthi Krishna
Updated on 19-Nov-2019 07:59:06

1K+ Views

You can match non-digit character using the meta character "\D".Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example {    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.nextLine();       String regex = "\D";       //Compiling the regular expression       Pattern pattern = Pattern.compile(regex);       //Retrieving the matcher object       Matcher matcher = pattern.matcher(input);       int count = 0;       ... Read More

How to match digits using Java Regular Expression (RegEx)

Maruthi Krishna
Updated on 19-Nov-2019 07:56:43

2K+ Views

You can match digits in a given string using the meta character "\d" or by using the following expression : [0-9]Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example {    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.nextLine();       String regex = "\d";       //Compiling the regular expression       Pattern pattern = Pattern.compile(regex);       //Retrieving the matcher object       Matcher matcher = pattern.matcher(input); ... Read More

Advertisements