- Trending Categories
- 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 4332 Articles for Java 8
63 Views
The toArray() method of the ArrayBlockingQueue class returns an array containing all of the elements in this queue.The syntax is as follows:Object[] toArray()To work with ArrayBlockingQueue class, you need to import the following package:import java.util.concurrent.ArrayBlockingQueue;The following is an example to implement toArray() method of Java ArrayBlockingQueue class:Example Live Demoimport java.util.ArrayList; import 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); q.add(700); ... Read More
152 Views
The size() method of the AbstractCollection class returns the numbers of elements in the collection. The method returns Integer.MAX_VALUE if the total number of elemnts in the collection exceeds the Interger.MAX_VALUE.The syntax is as follows:public abstract int size()To work with AbstractCollection class in Java, import the following package:import java.util.AbstractCollection;The following is an example to implement AbstractCollection size() method in Java:Example Live Demoimport 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
187 Views
The length() method of the StringJoiner class in Java 8 is used to get the length of the current value of StringJoiner.To work with the StringJoiner in Java 8, import the following package:import java.util.StringJoiner;The syntax is as follows:public int length()First, create a StringJoiner:StringJoiner strJoin = new StringJoiner(", "); strJoin.add("US"); strJoin.add("India"); strJoin.add("Netherlands"); strJoin.add("Australia");Now, find the length of the StringJoiner i.e. the number of elements in it using the length() method:strJoin.length());The following is an example to implement StringJoiner length() method in Java:Example Live Demoimport java.util.StringJoiner; public class Demo { public static void main(String[] args) { // StringJoiner ... Read More
93 Views
An Octetclass is a Tuple of 8 element. It is in the JavaTuples library. The following is the declaration of the Octet class:public final class Octet extends Tuple implements IValue0, IValue1, IValue2, IValue3, IValue4, IValue5, IValue6, IValue7Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package:import org.javatuples.Octet;Some of its features include:TypesafeSerializableComparableIterableImmutableNote: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar ... Read More
375 Views
If you want to remove an element from the AbstractCollection classs, use the remove() method. It returns TRUE if the elements requested to be removed is successfully removed from the collection.The syntax is as follows:public boolean remove(Object ob)Here, ob is the element to be removed the from this Collection. Whereas, the class Object is the root of the class hierarchy.To work with AbstractCollection class in Java, import the following package:import java.util.AbstractCollection;The following is an example to implement AbstractCollection remove() method in Java:Example Live Demoimport java.util.Iterator; import java.util.ArrayList; import java.util.AbstractCollection; public class Demo { public static void main(String[] args) { ... Read More
228 Views
The merge() method of the StringJoiner class in Java 8 is used to merge the contents of the StringJoiner str, which is passed as a parameter. The content gets added as the next element.The syntax is as follows:public StringJoiner merge(StringJoiner str)Here, str is the StringJoiner content to be merged.To work with the StringJoiner in Java 8, import the following package:import java.util.StringJoiner;The following is an example to implement StringJoiner merge() method in Java:Example Live Demoimport java.util.StringJoiner; public class Demo { public static void main(String[] args) { // StringJoiner 1 StringJoiner strJoin1 = new StringJoiner(" "); ... Read More
103 Views
To insert element into the stream, you need to use the add() method of the IntStream.Builder.The syntax is as follows:default IntStream.Builder add(int t)Here, parameter t is the element to be inserted.Declare IntStream.Builder:IntStream.Builder builder = IntStream.builder();Add some elements to the Builder using add() method:builder.add(10); builder.add(25); builder.add(33); builder.add(42);The following is an example to implement IntStream.Builder add() method in JavaExample Live Demoimport java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream.Builder builder = IntStream.builder(); System.out.println("Elements in the stream..."); builder.add(10); builder.add(25); builder.add(33); builder.add(42); ... Read More
92 Views
Insert an element into IntStream using the IntStream.Builder accept() method. It adds element to the stream being built.The syntax is as follows:void accept(int t)Here, parameter t is the input argument.The elements are inserted as shown below in the stream:builder.accept(10); builder.accept(15); builder.accept(25); builder.accept(39); builder.accept(45);The following is an example to implement IntStream.Builder accept() method in Java:Example Live Demoimport java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream.Builder builder = IntStream.builder(); System.out.println("Elements of the stream..."); builder.accept(10); builder.accept(15); builder.accept(25); builder.accept(39); ... Read More
181 Views
To convert Primitive Array to Stream, you need to use the of() method.Let’s say the following is our Primitive Array:int[] myArr = new int[] { 20, 50, 70, 90, 100, 120, 150 };Now, use the of() method to convert the primitive array to stream:IntStream stream = IntStream.of(myArr);The following is an example to convert primitive array to stream in Java:Example Live Demoimport java.util.stream.IntStream; import java.util.*; public class Main { public static void main(String[] args) { int[] myArr = new int[] { 20, 50, 70, 90, 100, 120, 150 }; System.out.println("The Primitive Array = "+Arrays.toString(myArr)); ... Read More