- 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
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
696 Views
The subexpression/metacharacter “\G” matches the point where the last match finished.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main( String args[] ) { String regex = "\G[0-9]"; 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; String digits = ""; System.out.println("Digits in the previous match:"); while(m.find()) { ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
442 Views
The subexpression/metacharacter “\D” matches the non-digits.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main( String args[] ) { String regex = "\D"; String input = "This is sample text 12 24 56 89 24"; 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: 24Example 2import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
145 Views
The subexpression/metacharacter “\d” matches the digits.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main( String args[] ) { String regex = "\d 24"; String input = "This is sample text 12 24 56 89 24"; 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: 2Example 2Following is a Java program that ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
517 Views
The subexpression/metacharacter “\S” matches the non-white space characters.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main( String args[] ) { String regex = "\S"; String input = "Hello how are you 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: 38Example 2import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
104 Views
The subexpression/metacharacter “\s” matches the white space equivalent.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main( String args[] ) { String regex = "\s"; String input = "Hello how are you 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: 7Example 2The following example reads a string ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
937 Views
The subexpression/metacharacter “\W” matches the non-word characters.Example1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main(String args[]) { String regex = "\W!"; String input = "Hello how are you 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: 1Example2Following example reads 5 string values and prints those that contain ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
169 Views
The subexpression/metacharacter “\w” matches the word characters i.e. a to z and A to Z and 0 to 9.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main( String args[] ) { String regex = "\w to"; String input = "Hello how are you 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); ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
124 Views
The subexpression/metacharacter “[^...]” matches any single character, not in brackets.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class SpecifiedCharacters { public static void main( String args[] ) { String regex = "[^hwtyoupi]"; String input = "Hi how are you 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: 21Example 2The following Java program accepts ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
94 Views
The subexpression/metacharacter “re*” matches 0 or more occurrences 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 = "aabc*"; String input = "aabcabcaabcabbcaabcbcaabc"; 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: 4Example 2import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatchAllCharacters ... Read More
![raja](https://www.tutorialspoint.com/assets/profiles/107595/profile/60_161286-1564642329.jpg)
1K+ Views
The @ConstructorProperties annotation is from java.beans package, used to deserialize JSON to java object via the annotated constructor. This annotation supports from Jackson 2.7 version onwards. The way this annotation works very simple, rather than annotating each parameter in the constructor, we can provide an array with the properties names for each of the constructor parameters.Syntax@Documented @Target(value=CONSTRUCTOR) @Retention(value=RUNTIME) public @interface ConstructorPropertiesExampleimport com.fasterxml.jackson.databind.ObjectMapper; import java.beans.ConstructorProperties; public class ConstructorPropertiesAnnotationTest { public static void main(String args[]) throws Exception { ObjectMapper mapper = new ObjectMapper(); Employee emp = new Employee(115, "Raja"); String jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(emp); ... Read More