Ankith Reddy

Ankith Reddy

730 Articles Published

Articles by Ankith Reddy

Page 28 of 73

DoubleStream noneMatch() method in Java

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

The noneMatch() method of the DoubleStream class returns true if none of the elements of this stream match the provided predicate.The syntax is as followsboolean noneMatch(DoublePredicate predicate)Here, predicate is a stateless predicate to apply to elements of this stream. To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create DoubleStream and add some elements to the streamDoubleStream doubleStream = DoubleStream.of(15.8, 28.7, 35.7, 48.1, 78.9);Now, TRUE is returned if none of the element match the conditionboolean res = doubleStream.noneMatch(num -> num > 90); The following is an example to implement DoubleStream noneMatch() method in JavaExampleimport java.util.*; import java.util.stream.DoubleStream; public ...

Read More

IntStream rangeClosed() method in Java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 1K+ Views

The rangeClosed() class in the IntStream class returns a sequential ordered IntStream from startInclusive to endInclusive by an incremental step of 1. This includes both the startInclusive and endInclusive values.The syntax is as followsstatic IntStream rangeClosed(int startInclusive, int endInclusive)Here, startInclusive is the value including the first value and endInclusive is the value indicating the last value. To work with the IntStream class in Java, import the following packageimport java.util.stream.IntStream;The following is an example to implement IntStream rangeClosed() method in JavaExampleimport java.util.stream.IntStream; public class Demo { public static void main(String[] args) { ...

Read More

The listIterator() method of CopyOnWriteArrayList in Java starting at a specified position

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

The listIterator() method CopyOnWriteArrayList class returns a list iterator over the elements in this list, beginning at the specified position in the list.The syntax is as followspublic ListIterator listIterator(int index)Here, index is the index of the first element to be returned from the list 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 listIterator() method in Java. We have set the index as 3, therefore, the list would be iterated from index 3Exampleimport java.util.Iterator; import java.util.ListIterator; import java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) ...

Read More

The contains() method of CopyOnWriteArrayList in Java

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

The contains() method of the CopyOnWriteArrayList class is used to get the specified element. It returns TRUE if the element is in the List, else FALSE is returned.The syntax is as followsboolean contains(Object ob)Here, ob is the element to be checked for existence. 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 contains() method 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);       arrList.add(400); ...

Read More

The iterator() method of CopyOnWriteArrayList in Java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 172 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

ArrayBlockingQueue remainingCapacity() Method in Java

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

The remainingCapacity() method of the ArrayBlockingQueue class in Java is used to return the number of additional elements that the queue can adopt without blocking.The syntax is as followsint remainingCapacity()To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to implement remainingCapacity() method of Java ArrayBlockingQueue classExampleimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(10);       q.add(120);       q.add(400);       q.add(450);       q.add(500);       System.out.println("ArrayBlockingQueue = " + q); ...

Read More

ArrayBlockingQueue remove() method in Java

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

The remove() method of the ArrayBlockingQueue class in Java is used to remove a single instance of the specified element from this queue.The syntax is as followsboolean remove(Object ele)Here, ele is the element to be removed from the queue. To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to implement remove() method of Java ArrayBlockingQueue classExampleimport java.util.ArrayList; import java.util.Iterator; import java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(10);       q.add(120);       q.add(10);     ...

Read More

Loop through ArrayList in Java

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

The elements of the ArrayList can be accessed one by one by using a for loop. A program that demonstrates this is given as followsExampleimport java.util.ArrayList; import java.util.List; public class Demo {    public static void main(String[] args) {       ArrayList aList = new ArrayList();       aList.add("Sun");       aList.add("Moon");       aList.add("Star");       aList.add("Planet");       aList.add("Comet");       System.out.println("The ArrayList elements are:");       for (String s : aList) {          System.out.println(s);       }    } }OutputThe output of the above program ...

Read More

Insert all elements of other Collection to Specified Index of Java ArrayList

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

The elements of a Collection can be inserted at the specified index of the ArrayList using the method java.util.ArrayList.addAll(). This method has two parameters i.e. the specific index at which to start inserting the Collection elements in the ArrayList and the Collection itself.If there is an element already present at the index specified by ArrayList.addAll() then that element and all subsequent elements are shifted to the right to make the space for the Collection elements in the ArrayList.A program that demonstrates this is given as follow.Exampleimport java.util.ArrayList; import java.util.Vector; public class Demo {    public static void main(String[] args) { ...

Read More

Set vs HashSet vs TreeSet in Java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 21K+ Views

A Set is a generic set of values with no duplicate elements. A TreeSet is a set where the elements are sorted.A HashSet is a set where the elements are not sorted or ordered. It is faster than a TreeSet. The HashSet is an implementation of a Set.Set is a parent interface of all set classes like TreeSet, HashSet, etc.Exampleimport java.util.*; public class Demo {    public static void main(String args[]) {       int a[] = {77, 23, 4, 66, 99, 112, 45, 56, 39, 89};       Set s = new HashSet();       try ...

Read More
Showing 271–280 of 730 articles
« Prev 1 26 27 28 29 30 73 Next »
Advertisements