Maruthi Krishna has Published 951 Articles

Java program to delete duplicate lines in text file

Maruthi Krishna

Maruthi Krishna

Updated on 08-Jul-2024 12:02:44

2K+ Views

The interface set does not allow duplicate elements. The add() method of this interface accepts elements and adds to the Set object, if the addition is successful it returns true, if you try to add an existing element using this method, the addition operations fails returning false. Problem Statement Given ... Read More

How to get ArrayList<String> to ArrayList<Object> and vice versa in java?

Maruthi Krishna

Maruthi Krishna

Updated on 07-Jun-2024 10:28:55

706 Views

ArrayList to ArrayList Instead of the typed parameter in generics (T) you can also use “?”, representing an unknown type. These are known as wild cards you can use a wild card as − Type of parameter or, a Field or, a Local field. Using wild cards, you can convert ... Read More

How to create a directory hierarchy using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 12-Mar-2024 18:37:31

1K+ Views

The class named File of the java.io package represents a file or directory (path names) in the system. This class provides various methods to perform various operations on files/directories. The mkdir() method of this class creates a directory with the path represented by the current object. Creating directory hierarchy There ... Read More

Checking for valid email address using regular expressions in Java

Maruthi Krishna

Maruthi Krishna

Updated on 19-Feb-2024 04:14:12

72K+ Views

To verify whether a given input string is a valid e-mail id match it with the following is the regular expression to match an e-mail id −"^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$"Where, ^ matches the starting of the sentence.[a-zA-Z0-9+_.-] matches one character from the English alphabet (both cases), digits, "+", "_", "." and, "-" before ... Read More

Pattern UNICODE_CASE field in Java with Examples

Maruthi Krishna

Maruthi Krishna

Updated on 07-Dec-2023 10:03:09

783 Views

Enables Unicode-aware case folding. When you use this as flag value to the compile() method along with the CASE_INSENSITIVE flag and if you search for Unicode characters using regular expressions Unicode characters of both cases will be matched. Example import java.util.regex.Matcher; import java.util.regex.Pattern; public class UNICODE_CASE_Example { public static void main( String ... Read More

Pattern UNIX_LINES field in Java with Examples

Maruthi Krishna

Maruthi Krishna

Updated on 07-Dec-2023 09:56:32

215 Views

This flag enables Unix lines mode. In the Unix lines mode, only '' is used as a line terminator and ‘\r’ is treated as a literal character. Example 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class LTERAL_Example { public static void main(String[] args) { String input = "This ... Read More

Pattern UNICODE_CHARACTER_CLASS field in Java with examples

Maruthi Krishna

Maruthi Krishna

Updated on 06-Dec-2023 12:41:53

483 Views

Enables the Unicode version of Predefined character classes and POSIX character classes. Example import java.util.regex.Matcher; import java.util.regex.Pattern; public class UNICODE_CHARACTER_CLASS_Example { public static void main( String args[] ) { String regex = "\u00de"; //Compiling the regular expression ... Read More

Pattern CANON_EQ field in Java with examples

Maruthi Krishna

Maruthi Krishna

Updated on 06-Dec-2023 12:36:04

869 Views

The CANON_EQ field of the Pattern class matches two characters only if they are canonically equal. When you use this as flag value to the compile() method, two characters will be matched if and only if their full canonical decompositions are equal. Where canonical decomposition is one of the Unicode text ... Read More

Pattern LITERAL field in Java with examples

Maruthi Krishna

Maruthi Krishna

Updated on 05-Dec-2023 10:52:51

1K+ Views

Enables literal parsing of the pattern. In this, all the characters including escape sequences and, meta-characters don’t have any special meaning they are treated as literal characters. For example, normally if you search for the regular expression “^This” in the given input text it matches the lines starting with the word ... Read More

Pattern MULTILINE field in Java with examples

Maruthi Krishna

Maruthi Krishna

Updated on 05-Dec-2023 10:40:19

2K+ Views

Enables multiline mode in general, the ^ and $ meta characters matches the start and end of the given input with the specified characters irrespective of the number of lines in it. Example 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class MULTILINE_Example { public static void main( String args[] ) { ... Read More

1 2 3 4 5 ... 96 Next
Advertisements