Maruthi Krishna has Published 870 Articles

Java program to verify whether a given element exists in an array

Maruthi Krishna

Maruthi Krishna

Updated on 31-Jul-2024 17:29:29

1K+ Views

Given an array and one of its element as an input, write a Java program to check whether that element exists in given array or not. You can find any element from an array using search algorithms. In this article, we will use linear search and binary search algorithms. Using ... Read More

Java program to delete duplicate lines in text file

Maruthi Krishna

Maruthi Krishna

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

3K+ 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

946 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

2K+ 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

81K+ 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

1K+ 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 UNICODE_CHARACTER_CLASS field in Java with examples

Maruthi Krishna

Maruthi Krishna

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

682 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 MULTILINE field in Java with examples

Maruthi Krishna

Maruthi Krishna

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

3K+ 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

What is the easiest way to reverse a String in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Dec-2023 09:29:13

1K+ Views

Built-in reverse() method The StringBuffer class provides you a method named reverse(). It reverses the contents of the current StringBuffer object and returns the resultant StringBuffer object. It is the easiest way to reverse a Sting using Java. To do so − Instantiate the StringBuffer class by passing the required String as ... Read More

How to validate given date formats like MM-DD-YYYY using regex in java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Dec-2023 09:18:50

4K+ Views

The java.util.regex package of java provides various classes to find particular patterns in character sequences. The pattern class of this package is a compiled representation of a regular expression. To match a regular expression with a String this class provides two methods namely − compile() − This method accepts a string representing ... Read More

Previous 1 ... 3 4 5 6 7 ... 87 Next
Advertisements