Programming Articles - Page 2757 of 3366

Collectors toCollection() method in Java

Alshifa Hasnain
Updated on 31-Dec-2024 22:02:20

1K+ Views

In this article, we will learn the Collectors.toCollection() method in Java, an essential tool for collecting elements into a specific type of collection, such as a List, Set, or any other collection type. Java 8 introduced a new, powerful feature called Streams, which enables functional-style programming to process sequences of elements. One of the key utilities in the Streams API is the Collectors class. What is the Collectors.toCollection() Method? The Collectors.toCollection() method is a static method in the Collectors class that allows you to collect elements from a stream into a custom collection. public static Collector toCollection(Supplier collectionFactory) Here ... Read More

Convert number string to integers in C++

Farhan Muhamed
Updated on 18-Apr-2025 19:02:00

414 Views

There are several inbuilt functions and objects to convert a number string to an integer in C++. Every method has its own advantages and disadvantages. In this article, we will discuss all the approaches to convert a number string to an integer in C++ with example code and use cases. Number String to Integer Conversion Here is the list of approaches to convert a number string to an integer in C++, which we will be discussing in this article with stepwise explanation and complete example codes. Convert Using stoi() Function ... Read More

Convert an integer to a hex string in C++

Farhan Muhamed
Updated on 17-Apr-2025 18:33:36

23K+ Views

Hexadecimal is a base 16 numbering system that uses 16 digits (from 0 to 9, and then A to F) to represent numbers. It is commonly used in computing systems to represent and store data. In this article, we will learn how to convert a normal integer to a hexadecimal string using C++ program. Integer to Hex String Conversion Here is a list of approaches for converting an integer to a hexadecimal, which we will be discussing in this article with stepwise explanation and complete example codes. Using std::stringstream ... Read More

Convert a floating point number to string in C

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

9K+ 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 − ... Read More

The iterator() method of Java AbstractSequentialList class

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

103 Views

The iterator() method of the AbstractSequentialList class iterates over the elements in this list and returns it.The syntax is as followsIterator iterator()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 iterator() method in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; import java.util.Iterator; public class Demo {    public static void main(String[] args) {       AbstractSequentialList       absSequential = new LinkedList();       absSequential.add(10);       absSequential.add(25);       absSequential.add(60);       absSequential.add(70);       absSequential.add(195);       System.out.println("Elements ... Read More

DoubleStream flatMap() method in Java

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

148 Views

The flatMap() method of the DoubleStream class returns a stream with the results of replacing each element of this stream with the contents of a mapped stream formed by applying the provided mapping function to each element.The syntax is as followsDoubleStream flatMap(DoubleFunction

DoubleStream findFirst() method in Java

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

105 Views

The findFirst() method returns an OptionalDouble describing the first element of this stream. It returns an empty OptionalDouble if the stream is empty.The syntax is as followsOptionalDouble findFirst()Here, OptionalDouble is a container object which may or may not contain a double value.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;First, create a DoubleStream with some elementsDoubleStream doubleStream = DoubleStream.of(15.6, 30.2, 50.5, 78.9, 80.4, 95.8);Now, get the first element of this stream using the findFirst() methodOptionalDouble res = doubleStream.findFirst();The following is an example to implement DoubleStream findFirst() method in JavaExample Live Demoimport java.util.*; import java.util.stream.DoubleStream; public class Demo { ... Read More

Create LabelValue Tuple using with() method in Java

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

122 Views

You can create a LabelValue tuple using with() method as well. The parameter of the with() method is the label and value of the LabelValue class.Let us first see what we need to work with JavaTuples. To work with LabelValue class in JavaTuples, you need to import the following packageimport 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 JavaTuplesSteps − How to ... Read More

Check if a string contains a sub-string in C++

Farhan Muhamed
Updated on 17-Apr-2025 18:56:43

8K+ Views

A substring is a continues sequence of characters within a larger string. For example, the string "point" a substring of the string "TutorialsPoint". In this article, we will learn different approaches to check if a string contains a substring in C++. Here is a list of approaches for checking if a string contains a substring, which we will be discussing in this article with stepwise explanation and complete example codes. Using find() Using search() Using regex_search() Manual Substring ... Read More

Create Decade Tuple from another collection in Java

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

131 Views

To create Decade Tuple from another collection in Java, use the fromArray() or the fromCollection() method. Here, we will see how to create a Decade Tuple using the fromCollection() method. This method will allow us to crate a Decade Tuple from a List collection in Java.Let us first see what we need to work with JavaTuples. To work with Decade class in JavaTuples, you need to import the following packageimport org.javatuples.Decade;Note Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then RightClick Project -> Properties -> Java Build Path -> Add External Jars and upload ... Read More

Advertisements