Maruthi Krishna

Maruthi Krishna

500 Articles Published

Articles by Maruthi Krishna

Page 4 of 50

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

Maruthi Krishna
Maruthi Krishna
Updated on 07-Jun-2024 1K+ 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 ArrayList to ArrayList as − ArrayList stringList = (ArrayList)(ArrayList)(list); Example import java.util.ArrayList; import java.util.Iterator; import java.util.ListIterator; public class ArrayListExample { public static void main(String args[]) { //Instantiating an ArrayList object ...

Read More

Pattern UNICODE_CASE field in Java with Examples

Maruthi Krishna
Maruthi Krishna
Updated on 07-Dec-2023 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 args[] ) { String regex = "\u00de"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CASE|Pattern.CASE_INSENSITIVE); //Retrieving the matcher object String str[] = {"\u00de", "\u00fe", ...

Read More

Pattern UNICODE_CHARACTER_CLASS field in Java with examples

Maruthi Krishna
Maruthi Krishna
Updated on 06-Dec-2023 743 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 Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CHARACTER_CLASS); //Retrieving the matcher object String str[] = {"\u00de", "\u00fe", "\u00ee", "\u00ce"}; for (String ele : str) { Matcher matcher = pattern.matcher(ele); ...

Read More

Pattern CANON_EQ field in Java with examples

Maruthi Krishna
Maruthi Krishna
Updated on 06-Dec-2023 1K+ 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 normalization forms. Example 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class CANON_EQ_Example { public static void main( String args[] ) { String regex = "b\u0307"; //Compiling the regular expression Pattern pattern = Pattern.compile(regex, Pattern.CANON_EQ); ...

Read More

Pattern LITERAL field in Java with examples

Maruthi Krishna
Maruthi Krishna
Updated on 05-Dec-2023 2K+ 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 "This". 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 is the first line" + "This is the second line" ...

Read More

Pattern MULTILINE field in Java with examples

Maruthi Krishna
Maruthi Krishna
Updated on 05-Dec-2023 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[] ) { //String regex = "(^This)";//.*t$)"; String input = "2234 This is a sample text" + "1424 This second 2335 line" + "This id third 455 line" ...

Read More

Can I import same package twice? Will JVM load the package twice at runtime?

Maruthi Krishna
Maruthi Krishna
Updated on 23-Nov-2023 2K+ Views

In Java classes and interfaces related to each other are grouped under a package. Package is nothing but a directory storing classes and interfaces of a particular concept. For example, all the classes and interfaces related to input and output operations are stored in java.io package. Creating a Package You can group required classes and interfaces under one package just by declaring the package at the top of the Class/Interface (file) using the keyword package as − Example public class Sample{ public void demo(){ System.out.println("This is a method of the sample class"); } ...

Read More

Can we declare an interface with in another interface in java?

Maruthi Krishna
Maruthi Krishna
Updated on 22-Nov-2023 1K+ Views

An interface in Java is a specification of method prototypes. Whenever you need to guide the programmer or, make a contract specifying how the methods and fields of a type should be you can define an interface. To create an object of this type you need to implement this interface, provide body for all the abstract methods of the interface and obtain the object of the implementing class. Nested Interfaces Java allows declaring interfaces within another interface, these are known as nested interfaces. While implementing you need to refer to the nested interface as outerInterface.nestedInterface. Example In the following Java example, we have an interface with ...

Read More

How to create date object in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 14-Sep-2023 34K+ Views

Using the Date classYou can create a Date object using the Date() constructor of java.util.Date constructor as shown in the following example. The object created using this constructor represents the current time.ExampleLive Demoimport java.util.Date; public class CreateDate {    public static void main(String args[]) {             Date date = new Date();       System.out.print(date);    } }OutputThu Nov 02 15:43:01 IST 2018Using the SimpleDateFormat classUsing the SimpleDateFormat class and the parse() method of this you can parse a date string in the required format and create a Date object representing the specified date.ExampleLive Demoimport java.text.ParseException; ...

Read More

Difference between peek(), poll() and remove() method of Queue interface in java?

Maruthi Krishna
Maruthi Krishna
Updated on 06-May-2022 16K+ Views

This represents a collection that is indented to hold data before processing. It is an arrangement of the type First-In-First-Out (FIFO). The first element put in the queue is the first element taken out from it.The peek() methodThe peek() method returns the object at the top of the current queue, without removing it. If the queue is empty this method returns null.Example Live Demoimport java.util.Iterator; import java.util.LinkedList; import java.util.Queue; public class QueueExample {    public static void main(String args[]) {       Queue queue = new LinkedList();       queue.add("Java");       queue.add("JavaFX");       queue.add("OpenCV");   ...

Read More
Showing 31–40 of 500 articles
« Prev 1 2 3 4 5 6 50 Next »
Advertisements