Chandu yadav

Chandu yadav

810 Articles Published

Articles by Chandu yadav

Page 30 of 81

The toArray(T[] a) method of CopyOnWriteArrayList in Java

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

The difference between toArray() and toArray(T[] arr) of the CopyOnWriteArrayList class is that both the methods returns an array containing all of the elements in this collection, but the latter has some additional features i.e. the runtime type of the returned array is that of the specified array.The syntax is as followspublic T[] toArray(T[] arr)Here, the parameter arr is the array into which the elements of the list are to be stored.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 toArray() method in JavaExampleimport java.util.Arrays; import java.util.concurrent.CopyOnWriteArrayList; ...

Read More

ArrayBlockingQueue drainTo() Method in Java

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

The drainTo() method of the ArrayBlockingQueue class removes all available elements from this queue and adds them to the given collection. It returns the number of elements transferred.The syntax is as followsint drainTo(Collection

Read More

IntStream findFirst() method in Java

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

The findFirst() method in Java returns an OptionalInt describing the first element of this stream. If the stream is empty, an empty OptionalInt is returned.The syntax is as followsOptionalInt findFirst()Here, OptionalInt is a container object which may or may not contain an int value.To work with the IntStream class in Java, import the following packageimport java.util.stream.IntStream;For OptionalInt class, import the following packageimport java.util.OptionalInt;First, create an IntStream and add elementsIntStream intStream = IntStream.of(30, 45, 70, 80, 90, 120);Now, get the first element of this streamOptionalInt res = intStream.findFirst();The following is an example to implement IntStream findFirst() method in JavaExampleimport java.util.OptionalInt; import ...

Read More

IntStream map() method in Java

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 3K+ Views

The IntStream map() method returns the new stream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsIntStream map(IntUnaryOperator mapper)Here, mapper parameter is a non-interfering, stateless function to apply to each elementCreate an IntStream and add some elementsIntStream intStream1 = IntStream.of(20, 35, 40, 55, 60);Now, map it with the new IntStream and display the updated stream elements applying the condition in the map() functionIntStream intStream2 = intStream1.map(a -> (a + a));The following is an example to implement IntStream map() method in JavaExampleimport java.util.*; import java.util.stream.IntStream; public class Demo {    public ...

Read More

Insert the specified element at the specified position in Java CopyOnWriteArrayList

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

Using the add() method, insert the specified element at the specified position in the CopyOnWriteArrayList.The syntax is as followsvoid add(int index, E ele)Here, the parameter index is where you want to insert the element and ele is the element to be inserted to this list. To work with CopyOnWriteArrayList class, you need to import the following packageimport java.util.concurrent.CopyOnWriteArrayList;The following is an example to add elements in the CopyOnWriteArrayList class in JavaExampleimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList arrList = new CopyOnWriteArrayList();       arrList.add(100);       arrList.add(250);   ...

Read More

LongStream sum() method in Java

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 129 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

LongStream.Builder accept() method in Java

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

The accept() method of the LongStream.Builder class adds an element to the stream being built.The syntax is as followsvoid accept(long i)Here, i is the input.To use the LongStream.Builder class in Java, import the following packageimport java.util.stream.LongStream;Create a LongStreamLongStream.Builder builder = LongStream.builder();Add some elementsbuilder.accept(200L); builder.accept(600L); builder.accept(400L);The following is an example to implement LongStream.Builder accept() method in JavaExampleimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream.Builder builder = LongStream.builder();       builder.accept(200L);       builder.accept(600L);       builder.accept(400L);       builder.accept(350L);       builder.accept(900L);       builder.accept(850L);   ...

Read More

DoubleStream mapToInt() method in Java

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

The mapToInt() function of the DoubleStream class returns an IntStream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsIntStream mapToInt(DoubleToIntFunction mapper)Here, mapper is a stateless function to apply to each element. The DoubleToIntFunction is a function that accepts a double-valued argument and produces an int-valued result.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream mapToInt() method in JavaExampleimport java.util.stream.IntStream; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream = DoubleStream.of(45.8, 78.9, ...

Read More

DoubleStream sorted() method in Java

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

The sorted() method of the DoubleStream class returns a stream consisting of the elements of this stream in sorted order.The syntax is as followsDoubleStream sorted()To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create a DoubleStream and add some elements to the streamDoubleStream doubleStream = DoubleStream.of(78.9, 90.4, 27.9, 20.6, 45.3, 18.5);Now, sort the elements of the streamdoubleStream.sorted().The following is an example to implement DoubleStream sorted() method in JavaExampleimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream = DoubleStream.of(78.9, 90.4, 27.9, 20.6, 45.3, 18.5);       System.out.println("Sorted ...

Read More

DoubleStream.Builder add() method in Java

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

The add() method of the DoubleStream.Builder class in Java adds an element to the stream being built. The method returns this builder.The syntax is as followsdefault DoubleStream.Builder add(double ele)Here, ele is the element to be added to this stream.To use the DoubleStream.Builder class in Java, import the following packageimport java.util.stream.DoubleStream; Create DoubleStream.Builder: DoubleStream.Builder builder = DoubleStream.builder(); Now add some elements: builder.add(23.5); builder.add(33.1); builder.add(35.6); builder.add(53.1);The following is an example to implement DoubleStream.Builder add() method in JavaExampleimport java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream.Builder builder = DoubleStream.builder();       builder.add(23.5);     ...

Read More
Showing 291–300 of 810 articles
« Prev 1 28 29 30 31 32 81 Next »
Advertisements