![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9326 Articles for Object Oriented Programming
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
205 Views
The toArray() method returns an array containing the elements of this stream.Set the elements in the stream with the IntStream class of() method.IntStream stream = IntStream.of(20, 40, 60, 70, 100, 120, 140);Now, display an array with the elements of this stream using the toArray() method.int[] myArr = stream.toArray();The following is the syntax.int[] toArray()The following is an example to implement IntStream toArray() method in Java.Example Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream stream = IntStream.of(20, 40, 60, 70, 100, 120, 140); int[] myArr = stream.toArray(); System.out.println(Arrays.toString(myArr)); } }Output[20, 40, 60, 70, 100, 120, 140]
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
180 Views
It can be checked if the days, months and years in the Period are negative or not using the isNegative() method in the Period class in Java. This method requires no parameters. Also, it returns true if any of the days, months and years in the Period are negative and false if all of the days, months and years in the Period are positive.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo { public static void main(String[] args) { String period = "P5Y9M4D"; Period p = Period.parse(period); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
690 Views
The mapToDouble() method returns a DoubleStream consisting of the results of applying the given function to the elements of this stream.The syntax is as follows.DoubleStream mapToDouble(IntToDoubleFunction mapper)Here, the parameter mapper is the stateless function applied to each element.Create an IntStream with some elements.IntStream intStream = IntStream.of(5, 20, 25, 45, 60, 75, 85, 90);Now, use the mapToDouble() method to return a DoubleStream.DoubleStream doubleStream = intStream.mapToDouble(val -> (double) val);The following is an example to implement IntStream mapToDouble() method in Java.Example Live Demoimport java.util.*; import java.util.stream.IntStream; import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { IntStream intStream ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
95 Views
The equality of two Periods can be determined using the equals() method in the Period class in Java. This method requires a single parameter i.e. the Period object to be compared. Also it returns true if both the Period objects are equal and false otherwise.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo { public static void main(String[] args) { String period1 = "P5Y7M15D"; Period p1 = Period.parse(period1); String period2 = "P5Y7M15D"; Period p2 = Period.parse(period2); System.out.println("The Period p1 ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
1K+ Views
The counting() method of the Java 8 Collectors class returns a Collector accepting elements of type T that counts the number of input elements.The syntax is as follows −static Collector counting()Here, the parameter −T − type of input elementsLong − This class value of the primitive type long in an objectTo work with Collectors class in Java, import the following package −import java.util.stream.Collectors;The following is an example to implement counting() method in Java 8 −Example Live Demoimport java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { Stream stream = Stream.of("25", "50", ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
89 Views
The peek() method of the ArrayBlockingQueue class returns the head of this queue or null if this queue is empty.The syntax is as follows.public E peek()To work with ArrayBlockingQueue class, you need to import the following package.import java.util.concurrent.ArrayBlockingQueue;The following is an example to implement peek() method of Java ArrayBlockingQueue class.Example Live Demoimport java.util.concurrent.ArrayBlockingQueue; public class Demo { public static void main(String[] args) throws InterruptedException { ArrayBlockingQueue q = new ArrayBlockingQueue(10); q.add(200); q.add(310); q.add(400); q.add(450); q.add(500); q.add(550); ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
121 Views
An immutable copy of the Period object where some days are added to it can be obtained using the plusDays() method in the Period class in Java. This method requires a single parameter i.e. the number of days to be added and it returns the Period object with the added days.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo { public static void main(String[] args) { String period = "P5Y7M15D"; Period p1 = Period.parse(period); System.out.println("The Period is: " + p1); Period p2 ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
74 Views
The allMatch() method in the DoubleStream class returns whether all elements of this stream match the provided predicate.The syntax is as follows −boolean allMatch(DoublePredicate predicate)Here, the argument predicate is a stateless predicate to apply to elements of this stream. The DoublePredicate is a predicate of one double-valued argument.To use the DoubleStream class in Java, import the following package −import java.util.stream.DoubleStream;Create DoubleStream and add some elements −DoubleStream doubleStream = DoubleStream.of(15.8, 28.7, 35.7, 48.1, 78.9);Now, check whether the condition is TRUE for elements of the stream −boolean res = doubleStream.allMatch(num -> num > 10); The following is an example to implement DoubleStream ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
41 Views
The allMatch() method in the LongStream class returns whether all elements of this stream match the provided predicate.The syntax is as follows.boolean allMatch(LongPredicate predicate)The parameter predicate is a stateless predicate to apply to elements of this stream. The LongPredicate represents a predicate of one long-valued argument.To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;The following is an example to implement LongStream allMatch() method in Java.Example Live Demoimport java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.of(100L, 150L, 200L, 300L, 400L, 500L); boolean res = longStream.allMatch(a ... Read More