Java Articles

Page 59 of 450

The add() method in Java Stream.Builder

Nancy Den
Nancy Den
Updated on 11-Mar-2026 606 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:Exampleimport 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

The accept() method in Java Stream.Builder

Nancy Den
Nancy Den
Updated on 11-Mar-2026 2K+ 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:Exampleimport 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

Convert Character Array to IntStream in Java

Nancy Den
Nancy Den
Updated on 11-Mar-2026 676 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:Exampleimport 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

Convert String to IntStream in Java

Nancy Den
Nancy Den
Updated on 11-Mar-2026 399 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:Exampleimport java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       String str = "Benz";       System.out.println("String to be converted = " + str);       System.out.println("String ...

Read More

Program to convert Primitive Array to Stream in Java

Nancy Den
Nancy Den
Updated on 11-Mar-2026 297 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:Exampleimport 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

What is the IntStream.Builder accept() method in Java

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 184 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:Exampleimport 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);       builder.accept(45); ...

Read More

IntStream.Builder add() method in Java

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 189 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 JavaExampleimport 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

StringJoiner merge() method in Java 8

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 364 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:Exampleimport java.util.StringJoiner; public class Demo {    public static void main(String[] args) {       // StringJoiner 1       StringJoiner strJoin1 = new StringJoiner(" ");   ...

Read More

The size() method of Java AbstractCollection class

Daniol Thomas
Daniol Thomas
Updated on 11-Mar-2026 230 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:Exampleimport 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

The addAll() method of Java AbstractSequentialList class

Daniol Thomas
Daniol Thomas
Updated on 11-Mar-2026 156 Views

The addAll() method of the AbstractSequentialList class inserts all the elements in the specified collection into this list at the specified position. Set the specified position as the parameter.The syntax is as follows:boolean addAll(int index, Collection

Read More
Showing 581–590 of 4,498 articles
« Prev 1 57 58 59 60 61 450 Next »
Advertisements