Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Java Articles
Page 57 of 450
ArrayBlockingQueue remainingCapacity() Method in Java
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 MoreThe hashCode() method of CopyOnWriteArrayList method in Java
To get the hash code value of the list, you need to use the hashCode() method of the CopyOnWriteArrayList class.The syntax is as followspublic int hashCode()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 hashCode() method in JavaExampleimport java.util.concurrent.CopyOnWriteArrayList; public class Demo { public static void main(String[] args) { CopyOnWriteArrayList arrList = new CopyOnWriteArrayList(); arrList.add(30); arrList.add(40); arrList.add(60); arrList.add(70); arrList.add(90); arrList.add(100); arrList.add(120); ...
Read MoreDoubleStream anyMatch() method in Java
The anyMatch() method of the DoubleStream class returns whether any elements of this stream match the provided predicate.The syntax is as followsboolean anyMatch(DoublePredicate predicate)Here, the parameter predicate is a stateless predicate to apply to elements of this stream. The DoublePredicate here is a predicate of one double-valued argument.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(67.9, 89.9, 10.5, 95.8, 49.6);Now, check if any of the elements match the predicateboolean res = doubleStream.anyMatch(a -> a > 50);The following is an example to implement DoubleStream anyMatch() method ...
Read MoreThe codePoints() method in Java IntStream
The codePoint() method is used to display a stream of code point values from the given sequence.The syntax is as followsIntStream codePoints()To work with Java IntStream class, you need to import the following packageimport java.util.stream.IntStream;Here is our stringString myStr = "Example!";Now, get the code point valuesIntStream intStream = myStr.codePoints();The following is an example to implement codePoints() method in Java IntStreamExampleimport java.util.stream.IntStream; public class Demo { public static void main(String args[]) { String myStr = "Example!"; IntStream intStream = myStr.codePoints(); System.out.println("The following is the list of ASCII Values for the given ...
Read MoreArrayBlockingQueue remove() method in Java
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 MoreIntStream limit() method in Java
The limit() method of the IntStream class is used to return a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length. Here, maxSize is the parameter.The syntax is as followsIntStream limit(long maxSize)Here, the maxSize parameter is the count of elements the stream is limited to.At first, an IntStream is created with the range() method to set a sequential order of elementsIntStream intStream = IntStream.range(20, 40);Now, use the limit() method, whose parameter is the maxSize i.e. the count of elements the stream is limited tointStream.limit(8)The following is an example to implement IntStream limit() ...
Read MoreCollectors maxBy() method in Java 8
The maxBy() method of the Collectors class in Java 8 returns a Collector that produces the maximal element according to a given Comparator, described as an Optional.The syntax is as followsstatic Collector maxBy(Comparator
Read MoreThe toArray() method of Java AbstractCollection class
The toArray() method of the AbstractCollection class is used to return the elements in this collection. The elements are returned in the form of an array.The syntax is as followspublic Object[] toArray()To work with AbstractCollection class in Java, import the following packageimport java.util.AbstractCollection;At first, declare AbstractCollection and add some elementsAbstractCollection absCollection = new ArrayList(); absCollection.add("Laptop"); absCollection.add("Tablet"); absCollection.add("Mobile"); absCollection.add("E-Book Reader");Now, use the toArray() method to return the elements in the form of an arrayObject[] myArr = absCollection.toArray();The following is an example to implement AbstractCollection toArray() method in JavaExampleimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo { public static void main(String[] args) ...
Read MoreIntStream parallel() method in Java
The parallel() method of the IntStream class in Java returns an equivalent parallel stream. The method may return itself, either because the stream was already parallel, or because the underlying stream state was modified to be parallel.The syntax is as follows:IntStream parallel()Create an IntStream and you can use the range() method as well to set the range of elements:IntStream intStream = IntStream.range(20, 35);Now, use the parallel() method:intStream.parallel()The following is an example to implement IntStream parallel() method in JavaExampleimport java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.range(20, 35); ...
Read MoreLongStream parallel() method in Java
The parallel() method of the LongStream class in Java returns an equivalent stream that is parallel.The syntax is as follows:LongStream parallel()To use the LongStream class in Java, import the following packageExampleimport java.util.stream.LongStream;The following is an example to implement LongStream parallel() method in Java:import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.range(10L, 20L); System.out.println("Parallel LongStream = "); longStream.parallel().forEach(System.out::println); } }outputParallel LongStream = 16 15 10 17 11 13 12 19 18 14
Read More