Programming Articles - Page 2760 of 3366

IntStream empty() method in Java

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

167 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

15K+ 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

105 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

C++ Program to Check the Connectivity of Undirected Graph Using DFS

Jennifer Nicholas
Updated on 15-Apr-2025 18:12:55

4K+ Views

The Depth-First Search (DFS) is a graph traversal algorithm that starts at root node and explores as far as possible along each branch before moving to next branch. In this article, we will discuss how to check the connectivity of a graph using DFS traversal algorithm. Understanding Connectivity of a Graph A graph is said to be connected if there is a path between every pair of vertices. To check connectivity of a graph, we will try to traverse all nodes using any traversal algorithm. After completing the traversal, if there is any node, which is not visited, then ... Read More

How to add elements to AbstractSequentialList class at a specific position in Java?

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

116 Views

The AbstractSequentialList class has the add() method to add an element to the specific position.The syntax is as followsadd(int index, E ele)Here, index is where the element is to be inserted. The ele is the element to be inserted.To work with the AbstractSequentialList class in Java, you need to import the following packageimport java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList add() method in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] args) {       AbstractSequentialList absSequential = new LinkedList();       absSequential.add(0, 50);       absSequential.add(1, 30);     ... Read More

DoubleStream peek() method in Java

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

216 Views

The syntax is as followsDoubleStream peek(DoubleConsumer action)Here, DoubleConsumer is an operation that accepts a single double-valued argument and returns no result.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream peek() 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(28.7, 35.6, 48.3, 69.8, 75.8, 80.5, 90.8);       System.out.println("Elements in the stream...");       long num = doubleStream.peek(System.out::println).count();       System.out.println("Number of elements in the stream = " + num);    } ... Read More

The lastIndexOf() method of CopyOnWriteArrayList in Java

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

127 Views

The lastIndexOf() method returns the index of the last occurrence of the specified element in this list. It returns -1 if this list does not contain the element.The syntax is as followspublic int lastIndexOf(Object ob)Here, ob is the element. The return value would be the last index of this element.To work with CopyOnWriteArrayList class, you need to import the following packageimport java.util.concurrent.CopyOnWriteArrayList;The following is an example to implement CopyOnWriteArrayList class lastIndexOf() method in JavaExample Live Demoimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList       arrList = new CopyOnWriteArrayList();     ... Read More

The iterator() method of CopyOnWriteArrayList in Java

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

124 Views

The iterator() method is used to return an iterator over the elements in this list.The syntax is as followsIterator iterator()To work with CopyOnWriteArrayList class, you need to import the following packageimport java.util.concurrent.CopyOnWriteArrayList;The following is an example to implement CopyOnWriteArrayList class iterator() method in JavaExample Live Demoimport java.util.Arrays; import java.util.Iterator; import java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList       arrList = new CopyOnWriteArrayList();       arrList.add(50);       arrList.add(90);       arrList.add(150);       arrList.add(200);       arrList.add(350);       arrList.add(500);       arrList.add(650); ... Read More

What is KeyValue class in JavaTuples?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

105 Views

A KeyValue class is a Tuple of 2 elements i.e. a key and value. It is in the JavaTuples library. The following is the declaration −public final class KeyValue extends Tuple implements IValueKey, IValueValueLet us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following package −import 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 ... Read More

Iterate through LabelValue Tuple in Java

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

191 Views

To iterate through the LabelValue tuple value, use a simple for loop just like what we do in other collections. Let us first see what we need to work with JavaTuples. To work with LabelValue class in JavaTuples, you need to import the following package −import org.javatuples.LabelValue;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 JavaTuples −Steps − How to run JavaTuples ... Read More

Advertisements