Java Articles

Page 55 of 450

LongStream forEachOrdered() method in Java

Nishtha Thakur
Nishtha Thakur
Updated on 11-Mar-2026 145 Views

The forEachOrdered() method in Java performs an action for each element of this stream, guaranteeing that each element is processed in encounter order for streams that have a defined encounter order.The syntax is as follows −void forEachOrdered(LongConsumer action)Here, parameter wrapper is a non-interfering action to perform on the elements. LongConsumer represents an operation that accepts a single long-valued argument and returns no result.To use the LongStream class in Java, import the following package −import java.util.stream.LongStream;The following is an example to implement LongStream forEachOrdered() method in Java −Exampleimport java.util.*; import java.util.stream.LongStream; public class Demo {    public static void main(String[] ...

Read More

The isEmpty() method of Java AbstractCollection class

Nishtha Thakur
Nishtha Thakur
Updated on 11-Mar-2026 343 Views

The isEmpty() method of the AbstractCollection class checks whether the collection is empty or not i.e. whether it has zero elements. It returns if the Collectionn has no elements.The syntax is as follows −public boolean isEmpty()To work with AbstractCollection class in Java, import the following package −import java.util.AbstractCollection;The following is an example to implement AbstractCollection isEmpty() method in Java −Exampleimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("Laptop");       absCollection.add("Tablet");       absCollection.add("Mobile");       absCollection.add("E-Book Reader"); ...

Read More

The iterator() method of Java AbstractCollection class

Smita Kapse
Smita Kapse
Updated on 11-Mar-2026 197 Views

The iterator() method of the AbstractCollection class in Java is used to return an iterator over the elements contained in this collection.The syntax is as follows −public abstract Iterator iterator()To work with AbstractCollection class in Java, import the following package −import java.util.AbstractCollection;For Iterator, import the following package −import java.util.Iterator;The following is an example to implement the AbstractCollection iterator() method in Java −Exampleimport java.util.Iterator; import java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("Laptop");       absCollection.add("Tablet");       absCollection.add("Mobile");   ...

Read More

IntStream findAny() method in Java

Anvi Jain
Anvi Jain
Updated on 11-Mar-2026 204 Views

The findAny() method of the IntStream class in Java is used to return an OptionalInt describing some element of the stream, or an empty OptionalInt if the stream is empty.The syntax is as follows −OptionalInt findAny()Here, OptionalInt is a container object which may or may not contain an int value.Create an IntStream and add some elements −IntStream intStream = IntStream.of(20, 35, 50, 60, 80, 100);Now, return any of the element of the stream using findAny() in Java −OptionalInt res = intStream.findAny();The following is an example to implement IntStream findAny() method in Java −Exampleimport java.util.*; import java.util.stream.IntStream; public class Demo ...

Read More

DoubleStream.Builder accept() method in Java

Smita Kapse
Smita Kapse
Updated on 11-Mar-2026 178 Views

The accept() method of the DoubleStream class in Java adds an element to the stream being built.The syntax is as follows −void accept(double ele)Here, ele is the element to be inserted into the stream.To use the DoubleStream.Builder class in Java, import the following package −import java.util.stream.DoubleStream;The following is an example to implement DoubleStream.Builder() accept() method in Java −Exampleimport java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream.Builder builder = DoubleStream.builder();       builder.accept(12.9);       builder.accept(25.6);       builder.accept(35.8);       builder.accept(43.9);       builder.accept(56.3);     ...

Read More

The iterator() method of CopyOnWriteArrayList in Java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 164 Views

The iterator() method is used to return an iterator over the elements in this list.The syntax is as followsIterator iterator()To work with CopyOnWriteArrayList class, you need to import the following packageimport java.util.concurrent.CopyOnWriteArrayList;The following is an example to implement CopyOnWriteArrayList class iterator() method in JavaExampleimport java.util.Arrays; import java.util.Iterator; import java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList       arrList = new CopyOnWriteArrayList();       arrList.add(50);       arrList.add(90);       arrList.add(150);       arrList.add(200);       arrList.add(350);       arrList.add(500);       arrList.add(650);   ...

Read More

DoubleStream peek() method in Java

George John
George John
Updated on 11-Mar-2026 245 Views

The syntax is as followsDoubleStream peek(DoubleConsumer action)Here, DoubleConsumer is an operation that accepts a single double-valued argument and returns no result.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream peek() method in JavaExampleimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream = DoubleStream.of(28.7, 35.6, 48.3, 69.8, 75.8, 80.5, 90.8);       System.out.println("Elements in the stream...");       long num = doubleStream.peek(System.out::println).count();       System.out.println("Number of elements in the stream = " + num);    } }OutputElements ...

Read More

How to add elements to AbstractSequentialList class at a specific position in Java?

George John
George John
Updated on 11-Mar-2026 145 Views

The AbstractSequentialList class has the add() method to add an element to the specific position.The syntax is as followsadd(int index, E ele)Here, index is where the element is to be inserted. The ele is the element to be inserted.To work with the AbstractSequentialList class in Java, you need to import the following packageimport java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList add() method in JavaExampleimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] args) {       AbstractSequentialList absSequential = new LinkedList();       absSequential.add(0, 50);       absSequential.add(1, 30);       ...

Read More

DoubleStream sequential() method in Java

George John
George John
Updated on 11-Mar-2026 140 Views

The sequential() method of the DoubleStream class returns an equivalent stream that is sequential.The syntax is as followsDoubleStream sequential()To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create a DoubleStream and add some elementsDoubleStream doubleStream1 = DoubleStream.of(45.8, 67.9, 78.5, 90.6, 97.4);Now create an equivalent stream that is sequentialDoubleStream doubleStream2 = doubleStream1.sequential();The following is an example to implement DoubleStream sequential() method in JavaExampleimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream1 = DoubleStream.of(45.8, 67.9, 78.5, 90.6, 97.4);       DoubleStream doubleStream2 = doubleStream1.sequential();       System.out.println("Equivalent ...

Read More

LongStream sum() method in Java

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 130 Views

The sum() method of the LongStream class returns the sum of elements in this stream.The syntax is as followslong sum()To use the LongStream class in Java, import the following packageimport java.util.stream.LongStream;First, create an IntStream and add some elementsLongStream longStream = LongStream.of(100L, 30000L, 45000L, 55000L, 70000L);Now, add the elements of the streamlong res = longStream.sum();The following is an example to implement LongStream sum() method in JavaExampleimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream longStream = LongStream.of(100L, 30000L, 45000L, 55000L, 70000L);       long res = longStream.sum();       System.out.println("The sum ...

Read More
Showing 541–550 of 4,498 articles
« Prev 1 53 54 55 56 57 450 Next »
Advertisements