
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

584 Views
The subexpression/metacharacter “\E” ends the quoting begun with \Q. i.e. you can escape metacharacters in the regular expressions by placing them in between \Q and \E. For example, the expression [aeiou] matches the strings with vowel letters in it.Example Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class SampleProgram { public static void main( String args[] ) { String regex = "[aeiou]"; Scanner sc = new Scanner(System.in); System.out.println("Enter input string: "); String input = sc.nextLine(); //Creating a Pattern object Pattern pattern = ... Read More

124 Views
The PatternSyntaxException class represents an unchecked exception thrown in case of a syntax error in regex string. This class contains three main methods namely −getDescription() − Returns the description of the error.getIndex() − Returns the error index.getPattern() − Returns the regular expression pattern with error.getMessage() − Returns the complete message congaing the error, index, regular expression pattern with error, indication of the error in the pattern.Example Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; public class PatternSyntaxExceptionExample { public static void main(String args[]) { //Reading String from user System.out.println("Enter a String"); ... Read More

5K+ Views
In Java, the strings that are used to find the pattern are known as regular expressions. In this article, we will learn to check multiple regex patterns against an input, and it can be done by using 2 approaches. Using Metacharacter Using the List object Using Metacharacter The meta character "|" in Java regular expressions allows you to match more than one regular expression. For example, if you need to match a particular input text with more than one expression, you need to separate them using the following: exp1|exp2|exp3 Example ... Read More

376 Views
Following is the regular expression to match hexadecimal number greater than 10 with even length −^(?=.{10,255}$)(?:0x)?\p{XDigit}{2}(?:\p{XDigit}{2})*$Where,^ − Matches the starting of the sentence.(?=.{10,255}$) − String ending with characters with 10 to 255.\p{XDigit}{2} − Two hexa-decimal characters.(?:\p{XDigit}{2})* − 0 or more sequences of double hexa-decimal characters.$ − Matches the end of the sentence.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class JavaExample51 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String nums[] = new String[5]; for(int i=0; i

436 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 the UnaryOperator representing a particular operation performs the specified operation on all the elements of the current list and replaces the existing values with the resultant values.In the following example we are implementing the UnaryOperator interface and creating a custom unary operator object and trying to pass it as an ... Read More

85 Views
The java.util.regex.MatcheResult interface provides methods to retrieve the results of a match.You can get an object of this interface using the toMatchResult() method of the Matcher class. This method returns a MatchResult object which represents the match state of the current matcher.The end(int group) method of this interface accepts an integer representing a particular group and returns the offset before the first match occurred in the specified group.Example Live Demoimport java.util.Scanner; import java.util.regex.MatchResult; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main( String args[] ) { String regex = "(.*)(\d+)(.*)"; //Reading input ... Read More

407 Views
This character class \p{javaMirrored} matches upper case letters. This class matches the characters which returns true when passed as a parameter to the isMirrored() method of the java.lang.Character class.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { 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(); //Regular expression String regex = "[\p{javaMirrored}]"; //Compiling the regular expression Pattern pattern = ... Read More

467 Views
This character class \p{javaWhitespace} matches spaces. This class matches the characters which returns true when passed as a parameter to the isWhitespace() method of the java.lang.Character class.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { 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(); //Regular expression String regex = "[\p{javaWhitespace}]"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex); ... Read More

691 Views
This character class \p{javaUpperCase} matches upper case letters. This class matches the characters which returns true when passed as a parameter to the isUpperCase() method of the java.lang.Character class.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { 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(); //Regular expression String regex = "[\p{javaUpperCase}]"; //Compiling the regular expression Pattern pattern = ... Read More

934 Views
IntUnaryOperator represents a functional interface that takes an int value and returns another int value. It is defined in java.util.function package and used as an assignment target for a lambda expression or method reference. It contains one abstract method: applyAsInt(), two default methods: compose(), andThen() and one static method: identity().Syntax@FunctionalInterface public interface IntUnaryOperatorExampleimport java.util.function.IntUnaryOperator; public class IntUnaryOperatorLambdaTest1 { public static void main(String[] args) { IntUnaryOperator getSquare = intValue -> { // lambda expression int result = intValue * intValue; System.out.println("Getting square: "+ result); return result; }; ... Read More