Found 34472 Articles for Programming

LongStream.Builder add() method in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

96 Views

The add() method of the LongStream.Builder class in Java adds an element to the stream being built. The method returns this builder.The syntax is as followsdefault LongStream.Builder add(long i)Here, i is the input.To use the LongStream.Builder class in Java, import the following packageimport java.util.stream.LongStream;Create LongStream.Builder and add some elementsLongStream.Builder builder = LongStream.builder();Add some elements in the streambuilder.add(150L); builder.add(200L); builder.add(500L); builder.add(250L);The following is an example to implement LongStream.Builder add() method in JavaExample Live Demoimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream.Builder builder = LongStream.builder();       builder.add(150L);       builder.add(200L);   ... Read More

C program to print a string without any quote in the program

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

634 Views

This is another tricky problem. In this program, we will see how to print a string using C where no quotation marks are used.Here we are using macro function. We are defining a macro function like#define getString(x) #xThe getString() is a macro function. It returns x by converting it into a string. The # before x is denoting that the function will convert x into a string.Input: Take one string without quote Output: Print that string into consoleAlgorithmStep 1:Take a string without quote Step 2: Use macro function to print it into a string Step 3: EndExample Code Live Demo#include #define ... Read More

Create KeyValue Tuple from an array in Java

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

80 Views

To create KeyValue tuple from an array in Java, you need to use the fromArray() method. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following packageimport org.javatuples.KeyValue;Note 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 file. Refer the below guide for all the steps to run JavaTuplesSteps − How to run JavaTuples program in EclipseThe following is an example ... Read More

DoubleStream iterator() method in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

83 Views

The iterator() method of the DoubleStream class in Java returns an iterator for the elements of this stream.The syntax is as followsPrimitiveIterator.OfDouble iterator()Here, PrimitiveIterator.OfDouble is an Iterator specialized for double values.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream iterator() method in JavaExample Live Demoimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream = DoubleStream.of(50.6, 69.8, 81.8, 95.6, 106.9);       PrimitiveIterator.OfDouble res = doubleStream.iterator();       while (res.hasNext()) {          System.out.println(res.nextDouble());       }    } }Output50.6 69.8 81.8 95.6 106.9

LongStream sum() method in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:25

47 Views

The sum() method of the LongStream class returns the sum of elements in this stream.The syntax is as followslong sum()To use the LongStream class in Java, import the following packageimport java.util.stream.LongStream;First, create an IntStream and add some elementsLongStream longStream = LongStream.of(100L, 30000L, 45000L, 55000L, 70000L);Now, add the elements of the streamlong res = longStream.sum();The following is an example to implement LongStream sum() method in JavaExample Live Demoimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream longStream = LongStream.of(100L, 30000L, 45000L, 55000L, 70000L);       long res = longStream.sum();       System.out.println("The ... Read More

IntStream distinct() method in Java

George John
Updated on 30-Jul-2019 22:30:25

115 Views

The distinct() method in the IntStream class in Java returns a stream consisting of the distinct elements of this stream.The syntax is as followsIntStream distinct()Let’s say we have the following elements in the stream. Some of them are repeatedIntStream intStream = IntStream.of(10, 20, 30, 20, 10, 50, 80, 90, 100, 80);To get the distinct elements, use the IntStream distinct() method.The following is an example to implement IntStream distinct() method in JavaExample Live Demoimport java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.of(10, 20, 30, 20, 10, 50, 80, 90, 100, 80); ... Read More

C program to copy string without using strcpy() function

Nitya Raut
Updated on 30-Jul-2019 22:30:25

450 Views

In this section we will see how to copy a string to other string without using strcpy() function. To solve this problem we can write our own function that can act like strcpy(), but here we will follow some trick. We will use another library function to copy a string into another.The logic is very simple. Here we will use the sprintf() function. This function is used to print some value or line into a string, but not in the console. This is the only difference between printf() and sprintf(). Here the first argument is the string buffer. where we ... Read More

IntStream empty() method in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:25

114 Views

The empty() method of the IntStream class returns an empty sequential IntStream.The syntax is as followsstatic IntStream empty()This is how you can create an empty IntStreamIntStream intStream = IntStream.empty();Now, using the count() method you can check the count of elements in the stream, which is 0 since we created an empty streamIntStream intStream = IntStream.empty();The following is an example to implement IntStream empty() method in JavaExample Live Demoimport java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.empty();       System.out.println("The number of elements in the stream = "+intStream.count());    } ... Read More

C Program to convert a number to a string

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

13K+ Views

In this section we will see how to convert a number (integer or float or any other numeric type data) to a string.The logic is very simple. Here we will use the sprintf() function. This function is used to print some value or line into a string, but not in the console. This is the only difference between printf() and sprintf(). Here the first argument is the string buffer. where we want to save our data.Input: User will put some numeric value say 42.26 Output: This program will return the string equivalent result of that number like "42.26"AlgorithmStep 1: Take ... Read More

DoubleStream sequential() method in Java

George John
Updated on 30-Jul-2019 22:30:25

48 Views

The sequential() method of the DoubleStream class returns an equivalent stream that is sequential.The syntax is as followsDoubleStream sequential()To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create a DoubleStream and add some elementsDoubleStream doubleStream1 = DoubleStream.of(45.8, 67.9, 78.5, 90.6, 97.4);Now create an equivalent stream that is sequentialDoubleStream doubleStream2 = doubleStream1.sequential();The following is an example to implement DoubleStream sequential() method in JavaExample Live Demoimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream1 = DoubleStream.of(45.8, 67.9, 78.5, 90.6, 97.4);       DoubleStream doubleStream2 = doubleStream1.sequential();       ... Read More

Advertisements