Found 34475 Articles for Programming

The listIterator() method AbstractList class in Java at a specified position

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

74 Views

The listIterator() method of the AbstractList class in Java is used to return a list iterator over the elements in this list, beginning at the specified position in the list.The syntax is as follows.public ListIterator listIterator(int index)Here, index is the index of the first element to be returned from the list iterator, whereas, ListIterator is an iterator for lists.To work with the AbstractList class, import the following package.import java.util.AbstractList;For ListIterator, import the following package.import java.util.ListIterator;The following is an example to implement listIterator() method of the AbstractlList class in Java.Example Live Demoimport java.util.ArrayList; import java.util.ListIterator; import java.util.AbstractList; public class Demo {   ... Read More

C++ Program to Implement Priority_queue in STL

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

93 Views

Priority queues are a type of container adapters, in which the first element of the queue is the greatest of all elements in the queue. Elements are in also non decreasing order in the priority queue. An element with high priority is served before an element with low priority, in a priority queue.Functions and descriptions:Functions used here:    pq.size() = Returns the size of priority queue.    pq.insert) = It is used to insert elements to the priority queue.    pq.delete() = Deletes the value from the priority queue.    pq.top() = Returns a reference to the top most element ... Read More

ArrayBlockingQueue iterator() method in Java

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

168 Views

The iterator() method of the ArrayBlockingQueue class returns an iterator over the elements in this queue in proper sequence.The syntax is as follows.public Iterator iterator()To work with ArrayBlockingQueue class, you need to import the following package.import java.util.concurrent.ArrayBlockingQueue;The following is an example to implement iterator() method of Java ArrayBlockingQueue class.Example Live Demoimport java.util.ArrayList; import java.util.Iterator; import java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(10);       q.add(120);       q.add(10);       q.add(400);       q.add(450);       q.add(500);       q.add(550); ... Read More

C++ Program to Implement Prev_Permutataion in STL

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

77 Views

Prev_permutation in STL is used to rearrange the elements in the range [first, last] into the previous lexicographically smaller permutation. A permutation is each one of the N! possible arrangements the elements can take. Here is a C++ program to implement Prev_permutation in STL.AlgorithmBegin    Define one integer array variable elements[].    Get the number of data e from the user.    Initialize the array elements[] with e number of data from the keyboard.    Sort all the array elements.    Reverse the array elements.    Do       show(elements) //to display the current content of the array   ... Read More

Collectors partitioningBy() method in Java 8

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

1K+ Views

The partioningBy() method returns a Collector that partitions the input elements according to a Predicate, and organizes them into a Map.The syntax is as follows.static Collector partitioningBy(Predicate

C++ Program to Implement Pairs in STL

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

272 Views

Pair is a simple container which consists of two data object:‘first’ = The first element is referenced as ‘first’ ‘second’ = the second element and the order is fixed (first, second).Pair can be assigned, compared and copied. It is used to combine together two values which may be different in type.Syntax is: pairvariable name(datavalue1, datavalue2).AlgorithmBegin Write pairvariable name(datavalue1,datavalue2) Print the pairs EndExample Code#include using namespace std; int main() { pair value('a',7); pair fruit ("grapes",2.30); pair food ("pulao",200); cout

Collectors collectingAndThen() method in Java 8

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

784 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

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

275 Views

Next_permutation in STL is used to rearrange the elements in the range [first, last] into the next lexicographically greater permutation. A permutation is each one of the N! possible arrangements the elements can take. This is C++ program to implement Next_permutation in STL.AlgorithmBegin    Define one integer array variable elements[].    Get the number of data e from the user.    Initialize the array elements[] with e number of data from the keyboard.    Sort all the array elements.    do       show(elements, e) //to display the current content of the array    while (next_permutation(elements, elements + e)) ... Read More

C++ Program to Implement Multiset in STL

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

148 Views

A multiset is a type of associative container in which has multiple elements can have same values.Functions and descriptions:Functions are used here:    ms.size() = Returns the size of multiset.    ms.insert) = It is used to insert elements to the multiset.    ms.erase() = Removes the value from the multiset.    ms.find() = Returns an iterator to the search element in the multiset if found,    else returns the iterator to end.    ms.count() = Returns the number of matches element in the multiset.    ms.begin() = Returns an iterator to the first element in the multiset.    ms.end() ... Read More

IntStream mapToLong() method in Java

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

540 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

Advertisements