Nancy Den has Published 290 Articles

Replace '*' with '^' with Java Regular Expressions

Nancy Den

Nancy Den

Updated on 25-Jun-2020 15:01:20

2K+ Views

To replace *' with '^' using Java Regular Expressions, we need to use the replaceAll() method. The replaceAll() method returns a String replacing all the character sequence matching the regular expression and String after replacement.Declaration − The java.lang.String.replaceAll() method is declared as follows −public String replaceAll(String regex, String replaced)  Let ... Read More

Replace all words with another string with Java Regular Expressions

Nancy Den

Nancy Den

Updated on 25-Jun-2020 15:00:08

3K+ Views

To replace all words with another String using Java Regular Expressions, we need to use the replaceAll() method. The replaceAll() method returns a String replacing all the character sequence matching the regular expression and String after replacement.Declaration − The java.lang.String.replaceAll() method is declared as follows −public String replaceAll(String regex, String ... Read More

Removing a Preference from a Preference Node in Java

Nancy Den

Nancy Den

Updated on 25-Jun-2020 14:58:52

524 Views

In order to remove a preference from a preference node in Java, we use the remove() method. The remove method() removes all the values associated with the specified key in the preference node.Declaration − The java.util.prefs.Preferences.remove() method is declared as follows −public abstract void remove (String key)where key is the ... Read More

Determine if a Preference Node exists in Java

Nancy Den

Nancy Den

Updated on 25-Jun-2020 14:56:28

678 Views

In order to determine the existence a preference node in Java, we use the nodeExists() method. The nodeExists() method returns a boolean value. It returns true when the specified preference node exists in the same tree as this node.Declaration − The java.util.prefs.Preferences.remove() method is declared as follows −public abstract boolean ... Read More

Generate Random Integer Numbers in Java

Nancy Den

Nancy Den

Updated on 25-Jun-2020 14:52:47

6K+ Views

In order to generate Random Integer Numbers in Java, we use the nextInt() method of the java.util.Random class. This returns the next random integer value from this random number generator sequence.Declaration − The java.util.Random.nextInt() method is declared as follows −public int nextInt()Let us see a program to generate random integer ... Read More

Convert a Queue to a List in Java

Nancy Den

Nancy Den

Updated on 25-Jun-2020 14:48:19

1K+ Views

In order to convert a Queue to a List in Java, we can create an LinkedList and pass the Queue as an argument in the parameterized constructor of an ArrayList. This can be done as follows −Queue q = new LinkedList(); List l = new ArrayList(q);The quickest way is used ... Read More

Rotate elements of a collection in Java

Nancy Den

Nancy Den

Updated on 25-Jun-2020 13:19:58

408 Views

To rotate elements of a collection in Java, we use the Collections.rotate() method. The rotate method rotates the elements specified in the list by a specified distance. When this method is invoked, the element at index x will be the element previously at index (x - distance) mod list.size(), for ... Read More

Create integer array with Array.newInstance in Java

Nancy Den

Nancy Den

Updated on 25-Jun-2020 13:13:53

243 Views

The java.lang.reflect.Array.newInstance(Class componentType, int length) method forms a new array with the component type and length as specified in the argumentsDeclaration − The java.lang.reflect.Array.newInstance(Class componentType, int length) method is declared as follows -public static Object newInstance(Class componentType, int length) throws IllegalArgumentException, NegativeArraySizeExceptionLet us see a program to create an integer ... Read More

Compare two float arrays in a single line in Java

Nancy Den

Nancy Den

Updated on 25-Jun-2020 12:29:39

211 Views

Two float arrays can be compared in Java using the java.util.Arrays.equals() method. This method returns true if the arrays are equal and false otherwise. The two arrays are equal if they contain the same number of elements in the same order.A program that compares two float arrays using the Arrays.equals() ... Read More

Check whether String is an interface or class in Java

Nancy Den

Nancy Den

Updated on 25-Jun-2020 12:27:18

628 Views

The method java.lang.Class.isInterface() is used to find if String is an interface or class in Java. This method returns true if String is an interface, otherwise it returns false.A program that demonstrates this is given as follows −Example Live Demopackage Test; import java.lang.*; public class Demo {    public static void ... Read More

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