Nancy Den

Nancy Den

178 Articles Published

Articles by Nancy Den

Page 4 of 18

LongStream generate() method in Java

Nancy Den
Nancy Den
Updated on 11-Mar-2026 175 Views

The generate() method of the LongStream class returns an infinite sequential unordered stream where each element is generated by the provided LongSupplier.The syntax is as follows:static LongStream generate(LongSupplier s)Here, s is the LongSupplier for generate elements. The LongSupplier is the supplier of long-valued results.To use the LongStream class in Java, import the following package:import java.util.stream.LongStream;The following is an example to implement LongStream generate() method in Java −Exampleimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args){       LongStream longStream = LongStream.generate(()          -> { return (long)(Math.random() * 100); });       System.out.println("Unordered ...

Read More

The containsAll() method of AbstractSequentialList in Java

Nancy Den
Nancy Den
Updated on 11-Mar-2026 157 Views

The containsAll() method of the AbstractSequentialList checks for all the elements in this collection. It returns TRUE if all this collection contains all the elements in the specified collection i.e. if the two collections are same.The syntax is as follows:public boolean containsAll(Collection c)Here, c is the collection to be checkedTo work with the AbstractSequentialList class in Java, you need to import the following package:import java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList containsAll() method in Java:Exampleimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] args) {       AbstractSequentialList absSequential = new LinkedList();     ...

Read More

What is AbstractList Class in Java?

Nancy Den
Nancy Den
Updated on 11-Mar-2026 840 Views

The AbstractList class provides an implementation of the List interface.For an unmodifiable listProgrammer needs to extend this class and provide implementations for the get(int) and size() methods.For a modifiable listProgrammer must override the set(int, E) method. If the list is variable-size the programmer must override the add(int, E) and remove(int) methods.The following is the syntax:public abstract class AbstractList extends AbstractCollection implements ListTo work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement AbstractList class:Exampleimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = ...

Read More

How to add elements to AbstractList class in Java?

Nancy Den
Nancy Den
Updated on 11-Mar-2026 469 Views

To add elements to AbstractList class, the add() method is provided by the AbstractList class. The elemnt gets appended at the end of the list.The syntax is as follows:public boolean add(E ele)Here, the parameter ele is an element to be appended to this listTo work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to add elements to AbstractlList class in Java:Exampleimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new LinkedList();       myList.add(50);       myList.add(100);       myList.add(150); ...

Read More

Can we override a private or static method in Java

Nancy Den
Nancy Den
Updated on 11-Mar-2026 9K+ Views

No, we cannot override private or static methods in Java.Private methods in Java are not visible to any other class which limits their scope to the class in which they are declared.ExampleLet us see what happens when we try to override a private method −class Parent {    private void display() {       System.out.println("Super class");        } } public class Example extends Parent {    void display() // trying to override display() {       System.out.println("Sub class");    }    public static void main(String[] args) {       Parent obj = new Example();   ...

Read More

Java 8 Stream Terminal Operations

Nancy Den
Nancy Den
Updated on 11-Mar-2026 9K+ Views

Streams in Java have a few terminal operations. They are as follows −collect − The collect method returns the outcome of the intermediate operationsList id = Arrays.asList(“Classes", "Methods", "Members"); List output = id.stream().filter(s -> s.startsWith("M")).collect(Collectors.toList());reduce − The reduce method is reduces the elements of a stream into a single element having a certain value after computation. The BinaryOperator is an argument of the reduce method.List list1 = Arrays.asList(11, 33, 44, 21); int even = list1.stream().filter(x -> x % == 0).reduce(0, (ans, i) -> ans+i);forEach − This method iterates through every element in the streamList list1= Arrays.asList(1, 3, 5, 7); List ...

Read More

Convert Unicode to UTF-8 in Java

Nancy Den
Nancy Den
Updated on 11-Mar-2026 13K+ Views

Before moving onto their conversions, let us learn about Unicode and UTF-8.Unicode is an international standard of character encoding which has the capability of representing a majority of written languages all over the globe. Unicode uses hexadecimal to represent a character. Unicode is a 16-bit character encoding system. The lowest value is \u0000 and the highest value is \uFFFF.UTF-8 is a variable width character encoding. UTF-8 has the ability to be as condensed as ASCII but can also contain any Unicode characters with some increase in the size of the file. UTF stands for Unicode Transformation Format. The '8' signifies ...

Read More

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

Nancy Den
Nancy Den
Updated on 11-Mar-2026 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 us see a program to replace '*' with '^' using Java Regular Expressions −Examplepublic class Example {    public static void main( String args[] ) {       String str = new String("H*e*l*l*o");       System.out.println( "Initial String : "+ str);       // replacing '*' with ...

Read More

Removing a Preference from a Preference Node in Java

Nancy Den
Nancy Den
Updated on 11-Mar-2026 611 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 key whose preference is to be removedThe remove methods throws the following exceptions −NullPointerExceptionThis exception occurs when the key is nullIllegalStateExceptionThis exception is thrown when the ancestor node is removed by the removeNode() method.Let us see a program to remove the preference from a preference node −Exampleimport java.util.prefs.Preferences; public class ...

Read More

Determine if a Preference Node exists in Java

Nancy Den
Nancy Den
Updated on 11-Mar-2026 738 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 nodeExists(String pathname)throws BackingStoreExceptionwhere pathname is the path name of the node whose existence needs to be determined.Let us see a program to determine if a preference node exists in Java −Exampleimport java.util.prefs.Preferences; public class Example {    public static void main(String[] args) throws Exception {       boolean exist ...

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