Programming Articles - Page 2745 of 3366

C++ Program to Implement Pairs in STL

Farhan Muhamed
Updated on 09-May-2025 15:38:46

481 Views

A pair is a container provided by the Standard Template Library (STL) in C++ that stores two heterogeneous objects as a single unit. In this article, we will learn how to use a pair from the Standard Template Library (STL) in C++. What is Pair? Pair is a utility container defined in the header that is used to store two related data elements or objects in pairs. The first element will be referenced as first, and the second element will be referenced as second. It is commonly used to return two values from a function using a single ... Read More

Collectors collectingAndThen() method in Java 8

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

1K+ Views

The collectingAndThen() method in Java Collectors class acclimates a Collector to perform an additional finishing transformation. It returns collector which performs the action of the downstream collector, followed by an additional ending step.The syntax is as follows.static Collector collectingAndThen(Collector downstream, Function finisher)Here, the parameter, T − Type of the input elementsA − Intermediate accumulation type of the downstream collectorR − The result type of the downstream collectorRR − The result type of the resulting collectordownstream − Collectorfinisher − A function to be applied to the final result of the downstream collectorTo work with Collectors class in Java, import the ... Read More

C++ Program to Implement Next_Permutation in STL

Farhan Muhamed
Updated on 09-May-2025 15:38:15

461 Views

Next permutation is an algorithmic operation that rearranges the elements of a range into the next lexicographically greater permutation. In this article, we will learn how to use the next_permutation() function from the Standard Template Library (STL) in C++. What is Next Permutation? The Next Permutation is an operation used to generate all the possible permutations an array in lexicographical order. A permutation is the one of N! arrangements of the elements in an array of size N. If the current sequence is the last permutation, the function transforms it into the first one (i.e., sorted in ascending order). ... Read More

C++ Program to Implement Multiset in STL

Farhan Muhamed
Updated on 07-May-2025 18:29:43

288 Views

A multiset is an associative container that stores data in a sorted order in such a way that it allows duplicate values in the set. In this article, we will learn how to use a multiset from the Standard Template Library (STL) in C++. What is Multiset? Multiset is a sorted associative container that allows storing multiple elements with the same value. The values are automatically arranged in sorted order. This makes it useful in scenarios where you need to keep count of repeated values while maintaining order. For example, we can store the scores of students even ... Read More

IntStream mapToLong() method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

732 Views

The mapToLong() function in IntStream class returns a LongStream consisting of the results of applying the given function to the elements of this stream.The syntax is as follows.LongStream mapToLong(IntToLongFunction mapper)Here, the parameter mapper is a stateless function to apply to each element.Create an IntStream with some elements in the Stream.IntStream intStream = IntStream.of(50, 100, 150, 200);Now create a LongStream and use the mapToLong() with a condition.LongStream longStream = intStream.mapToLong(num → (long)num);The following is an example to implement IntStream mapToLong() method in Java.Exampleimport java.util.*; import java.util.stream.IntStream; import java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {     ... Read More

C++ Program to Implement Multimap in STL

Farhan Muhamed
Updated on 07-May-2025 18:29:29

452 Views

A multimap is an associative container that stores elements in a key-value pair format, where multiple values can share the same key. In this article, we will learn how to use a multimap from the Standard Template Library (STL) in C++. What is Multimap? Multimap is a sorted associative container that stores data in key-value pairs, where keys can occur multiple times. Keys are stored in sorted order, and you can insert, access, and remove elements based on the key. For example, in a multimap we can store student names with their scores even if some students have ... Read More

IntStream mapToObj() method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

3K+ Views

The mapToObj() method in the IntStream class returns an object-valued Stream consisting of the results of applying the given function to the elements of this stream.The syntax is as follows. StreammapToObj(IntFunction

LongStream iterator() method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

167 Views

The iterator() method of the LongStream class in Java returns an iterator for the elements of this stream.The syntax is as follows.PrimitiveIterator.OfLong iterator()Here, PrimitiveIterator is an Iterator specialized for long values.To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;The following is an example to implement LongStream iterator() method in Java.Example Live Demoimport java.util.*; import java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream longStream = LongStream.of(15000L, 17000L, 25000L);       PrimitiveIterator.OfLong i = longStream.iterator();       while (i.hasNext()) {          System.out.println(i.nextLong());       }   ... Read More

C++ Program to Implement Map in STL

Farhan Muhamed
Updated on 07-May-2025 18:29:15

4K+ Views

A map is an associative container that stores elements in a key-value pair format. Each element has a unique key and a corresponding mapped value. No two mapped values can have the same key. In this article, we will learn how to use a map from the Standard Template Library (STL) in C++. What is Map? Map is a sorted associative container that contains key-value pairs with unique keys. Keys are sorted automatically, and each key is associated with a value. You can insert, access, and remove elements based on the key. For example, we can store ... Read More

Create Octet Tuple using with() method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

118 Views

You can easily create Octet Tuple in Java using with() method. Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package.import org.javatuples.Octet;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 program in EclipseThe following is an example to create Octet Tuple using with() ... Read More

Advertisements