
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 7442 Articles for Java

475 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

318 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

150 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

146 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

266 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

351 Views
If you have a string and you want to convert it into IntStream with ASCII values, then it can be easily achieved using the below code.To work with IntStream class, you need to import the following package:import java.util.stream.IntStream;Let’s say the following is our string:String str = "Benz";Convert the above string to IntStream:IntStream stream = str.chars();The following is an example to convert String to IntStream in Java:Example Live Demoimport java.util.stream.IntStream; public class Demo { public static void main(String[] args) { String str = "Benz"; System.out.println("String to be converted = " + str); ... Read More

608 Views
Let’s say the following is our character array:Character arr[] = { 'V', 'e', 'h', 'i', 'c', 'l' , 'e' };To convert the above character array to IntStreamIntStream stream = Stream.of(arr).flatMapToInt(IntStream::of);We have used the flatMapToInt() method for this.The following is an example to convert character array to IntStream in Java:Example Live Demoimport java.util.stream.*; public class Main { public static void main(String[] args) { Character arr[] = { 'V', 'e', 'h', 'i', 'c', 'l' , 'e' }; System.out.println("The character array = "); for (char value : arr) { System.out.println("Value ... Read More

164 Views
The build() method of the LongStream.Builder class builds the stream and returns the built stream. The following is the syntax:LongStream build()Import the following package for the LongStream.Builder class in Java:import java.util.stream.LongStream;Declare a LongStream.Builder and add elements:LongStream.Builder builder = LongStream.builder(); builder.add(24000L); builder.add(47470L); builder.add(12999L);Now, use the build() method to build the stream:builder.build()The following is an example displaying how to implement build() method of LongStream.Builder in Java:Example Live Demoimport java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream.Builder builder = LongStream.builder(); builder.add(24000L); builder.add(47470L); builder.add(12999L); ... Read More

1K+ Views
Add an element to the stream using the accept() method of Java Stream.Builder.The following is the syntax:void accept(T t)Here, t is the argument to be inserted.Import the following package for the Stream.Builder class in Java:import java.util.stream.Stream;First, declare a Stream.Builder:Stream.Builder builder = Stream.builder();Now, use the accept() method:builder.accept("Demo"); builder.accept("Text");The following is an example displaying how to implement accept() method of Stream.Builder in Java:Example Live Demoimport java.util.stream.Stream; public class Demo { public static void main(String[] args){ Stream.Builder builder = Stream.builder(); builder.accept("Demo"); builder.accept("Text"); Stream str = builder.build(); str.forEach(System.out::println); ... Read More

572 Views
Use the add() method to insert elements in the Stream.Builder. The element to be added is a parameter for the add().The following is the syntax:default Stream.Builder add(T t)Here, t is the element to be added.Import the following package for the Stream.Builder class in Java:import java.util.stream.Stream;At first, create Stream.Builder:Stream.Builder builder = Stream.builder();Now, add elements using add() method:builder.add("This"); builder.add("is"); builder.add("it!");Here is an example displaying how to implement add() method of Stream.Builder in Java:Example Live Demoimport java.util.stream.Stream; public class Demo { public static void main(String[] args) { Stream.Builder builder = Stream.builder(); builder.add("This"); builder.add("is"); ... Read More