Tag: over
Iterating over a range of User Defined objects and calling member function using std::for_each
In this article we will discuss how to iterate over a container of user defined objects and call a member function on each of the iterating element.Suppose you have a vector of Employee class objects and you want to call a member function on each of the element in vector. [showads ad=inside_post] Let’s see how …
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 …
map vs unordered_map | When to choose one over another ?
In this article we will compare std::map and std::unordered_map and will also discuss when to choose one over another. Both std::map & std::unordered_map store elements in key value pair & provide member functions to efficiently insert, search & delete key value pairs. Advertisements But they are different in following areas, Internal Implementation Memory Usage Time …
map vs unordered_map | When to choose one over another ?Read More
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 …