Tag: Iterate
How to iterate LinkedList in reverse or backward direction
In this article we will discuss how to iterate over a LinkedList in reverse order. Method 1 : Using Descending Iterator Iterator<E> descendingIterator() Descending Iterator returns the Iterator that points to the end of of List i.e. LinkedList<String> listOfStr = new LinkedList<>(); // Get Descending List Iterator from List Object Iterator<String> listItReverse = listOfStr.descendingIterator(); Now calling function …
How to iterate LinkedList in reverse or backward directionRead More
How to iterate over a LinkedList in Java
In this article we will discuss how to iterate over a LinkedList Collection in Java and access objects. To fetch the Iterator from a LinkedList object use following member function, Advertisements ListIterator<E> listIterator(); It will return ListIterator object that implements Iterator that provides functions to iterate over the LinkedList object. It manages an internal Cursor which is …
How to iterate over a HashSet in Java
In this article we will discuss how to Iterate over a HashSet in Java using HashSet. Fetch Iterator from HashSet To iterate over a HashSet we will use an Underlying Iterator object of the HashSet. Advertisements Fetch the Iterator from a HashSet object use its member function iterator() i.e. // Create a HashSet of String HashSet<String> …
How to iterate over an unordered_map in C++11
In this article we will discuss the different ways to iterate over an unordered_map. First lets create an unordered_map and then we will see the different ways to iterate over it. // Initialize an unordered_map through initializer_list std::unordered_map<std::string, int> wordMap({{ “First”, 1 },{ “Second”, 2 },{ “Third”, 3 }}); Iterating an unordered_map using range based …
How to Iterate over a map in C++
In this article we will discuss 3 different ways to Iterate over a map in C++. Suppose we have a map of string and int as key-value pair i.e. Advertisements std::map<std::string, int> mapOfWordCount; Now let’s see how to iterate over this map in 3 different ways i.e. Iterate over a map using STL Iterator First …
How to iterate a map in reverse order – C++
In this article we will discuss how to iterate a map in reverse order. Map store the elements in sorted order of keys. For example, if you store following elements in map i.e. Advertisements {“aaa”, 10}, {“ddd”, 11}, {“bbb”, 12}, {“ccc”, 13} It will internally store the elements in sorted order of keys i.e. {“aaa”, …
Different ways to iterate over a set in C++
In this article we will discuss different ways to iterate over a set in C++. Let’s create a set of strings i.e. Advertisements // Set of strings std::set<std::string> setOfStr = { “jjj”, “khj”, “bca”, “aaa”, “ddd” }; Now let’s iterate over it and print the contents on screen using different methods i.e. Iterating over a …
C++ : Different Ways to iterate over a List of objects
In this article we will discuss different ways to iterate through std::list of objects. Suppose we have a struct Player that contains id and name i.e. Advertisements struct Player { int id; std::string name; Player(int playerId, std::string playerName) : id(playerId), name(playerName) { } }; Lets create a list Player objects i.e. std::list<Player> listofPlayers = { …
C++ : Different Ways to iterate over a List of objectsRead More
Python : Different ways to Iterate over a List in Reverse Order
In this article we will discuss different ways to Iterate over a python list in reverse order. Suppose we have a python list of strings i.e. Advertisements # List of string wordList = [‘hi’, ‘hello’, ‘this’, ‘that’, ‘is’, ‘of’] Now we want to iterate over this list in reverse order( from end to start ) …
Python : Different ways to Iterate over a List in Reverse OrderRead More
Python : How to Iterate over a list ?
In this article we will discuss different ways to iterate over a list. Iterate over the list using for-in loop Its easies solution to iterate over the list i.e. Advertisements ”’ Iterate over the list using for loop ”’ for word in wordList: print(word) Output hi hello this that is of Iterate over the list …