Found 2617 Articles for Java

Custom UnaryOperator implementation in java.

Maruthi Krishna
Updated on 20-Feb-2020 12:04:09

306 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

MatchResult start(int group) method in Java with examples.

Maruthi Krishna
Updated on 10-Jan-2020 10:27:43

43 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

MatchResult start() method in Java with examples.

Maruthi Krishna
Updated on 10-Jan-2020 10:24:36

60 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 start() method of this interface returns the beginning index of the current match.Example Live Demoimport java.util.Scanner; import java.util.regex.MatchResult; import java.util.regex.Matcher; import java.util.regex.Pattern; public class StartExample {    public static void main(String args[]) {       //Reading String from user       System.out.println("Enter a String");       Scanner sc = new Scanner(System.in);       String input = ... Read More

Character class p{javaMirrored} Java regex.

Maruthi Krishna
Updated on 10-Jan-2020 10:20:10

300 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

Character class p{javaWhitespace} Java regex in java.

Maruthi Krishna
Updated on 10-Jan-2020 10:09:24

324 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

Character class p{javaUpperCase} Java regex.

Maruthi Krishna
Updated on 10-Jan-2020 10:05:40

513 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

Difference between super() and this() in java Program

Mahesh Parahar
Updated on 25-Feb-2020 06:13:14

9K+ Views

Along with various other keywords Java also provides this and super as special keywords which primarily used to represent current instance of a class and it's super class respectively. With this similarity both these keywords have significant differences between them which are listed as below - Sr. No.Keythissuper1Represent and Referencethis keyword mainly represents the current instance of a class.On other hand super keyword represents the current instance of a parent class.2Interaction with class constructorthis keyword used to call default constructor of the same class.super keyword used to call default constructor of the parent class.3Method accessibilitythis keyword used to access methods of ... Read More

Difference between Traditional Collections and Concurrent Collections in java

Mahesh Parahar
Updated on 24-Feb-2020 11:17:20

782 Views

In Java as we know that Collections are one of most important concept which makes Java as a powerful language in itself. It is only support of collections in Java which make it to support any type of data in a convenient and efficient way along with possible CRUD operations over them.But on same phase when collections get exposed to the multi-threading its performance get somewhat degraded because of somewhere collections lack the support to multi-threading environment. To overcome this limitation Java introduces Concurrent Collections which not only overcome the multi-threading environment limitation but also enhances the Java to perform ... Read More

Character class p{javaLowerCase} Java regex.

Maruthi Krishna
Updated on 10-Jan-2020 09:59:42

389 Views

This character class \p{javaLowerCase} matches lower case letters. This class matches the characters which returns true when passed as a parameter to the isLowerCase() 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{javaLowerCase}]";       //Compiling the regular expression       Pattern pattern = ... Read More

Posix character classes p{Space} Java regex.

Maruthi Krishna
Updated on 09-Jan-2020 10:43:03

361 Views

This class matches white space characters. i.e. \t, , \x, 0B, \f, \r.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class SpaceCharacters {    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{Space}]";       //Compiling the regular expression       Pattern pattern = Pattern.compile(regex);       //Retrieving the matcher object       Matcher matcher = pattern.matcher(input);   ... Read More

Advertisements