Found 33676 Articles for Programming

Private Methods in Python

SaiKrishna Tavva
Updated on 17-Oct-2024 13:05:14

2K+ Views

In object-oriented programming,  private methods are functions that act as access modifier within a class designed only for internal use and not accessible from outside the class. The functionality of private methods is primarily meant for encapsulation which means that they are hidden to prevent unwanted modifications and misuse. Working of Private Methods In Python, the convention to denote private methods is "_". We just need to prefix the method name with a single underscore (_) or, double underscores (__). Single underscore(_) : To indicate that ... Read More

Priority Queue using Queue and Heapdict module in Python

Niharika Aitam
Updated on 19-Oct-2023 11:45:08

471 Views

The priority Queue is the abstract data type which is similar to the queue or stack, in which each element is attached with a priority. Here the priority determines the order of the elements to be dequeued from the queue and the higher priority elements are dequeued before the elements with the lower priority. The priority queues will be implemented using different data structures such as heaps, arrays or balanced trees. The most commonly used implementation is the heap, which is the binary tree based data structure having the value of each node greater than or equal to the values ... Read More

How to Iterate the Vector Elements in the Reverse Order in Java?

Deepti S
Updated on 18-Oct-2023 16:35:11

286 Views

The Vector class has been a part of the Java collection system since Java version 1.2. Vectors are sometimes known as Dynamic Arrays because, unlike ordinary arrays, they can expand and contract in size. Ensuring thread-safety, Vectors are synchronized. While there exists a third approach that involves using Apache Commons to iterate through the vector in reverse, this method necessitates the downloading of additional jar files and packages, which is not widely supported by most systems. Essentially, there are only two primary methods to traverse through vector elements in reverse order. Methods Used There are two methods used here − ... Read More

How to Invoke Method by Name in Java Dynamically Using Reflection?

Deepti S
Updated on 18-Oct-2023 16:29:33

1K+ Views

The Reflection API in Java allows you to dynamically call any method using its string name. When using the java.lang.reflect API, you can load classes by name even if they aren't accessible at compile time thanks to reflection's robust mechanism. It empowers you to dynamically invoke any method using reflection and makes it possible you to retrieve all methods from a class, including private and public ones. Those who are unfamiliar with Java might find this idea strange. With no explicit code for calling the method during compilation, Java can execute a method when its name is provided as a ... Read More

How to iterate over a TreeMap in Java?

Aishwarya Naglot
Updated on 28-Jul-2025 18:51:44

3K+ Views

TreeMap is based on the Red-Black tree structure, which is a It is a part of the Java Collections Framework. It is a sorted map and maintains the order of its keys. Its order depends on the natural ordering of the keys or by a Comparator.Since the TreeMap is not a Collection, we cannot use the for-each loop to iterate through it. Instead, we can use the entrySet() method to get a set view of the mappings contained in the map, which we can then iterate over to access the keys and values. Let's explore some scenarios to understand the ... Read More

How to Iterate HashMap in Java?

Deepti S
Updated on 18-Oct-2023 16:24:21

866 Views

(Key, Value) pairs are used to store data in Java HashMap collections. Although it is unsynchronized, it is comparable to HashTable. As a result, a HashMap can be accessed by numerous threads without encountering any troubles. Despite the fact that HashMap allows for the storage of null keys as well, there can most effective be one null key object and an infinite wide variety of null values. regarding the order of the map, this class gives no guarantees. To index the value, the key is utilised. We can store unique keys with HashMap. If we try to insert one, the ... Read More

How to iterate HashSet in Java?

Aishwarya Naglot
Updated on 28-Jul-2025 16:09:59

3K+ Views

The HashSet class is a part of the Java Collections Framework, and it implements the Set interface. It is a collection of unique individual elements. It internally uses a hash table; therefore, the iteration order of elements is not guaranteed. Our task is to iterate through the elements of a HashSet in Java. Let's look at some scenarios to understand the problem better: Scenario 1 Input: {1, 2, 3, 4, 5} Output: 1 2 3 4 5 Explanation: The HashSet contains the elements 1, 2, 3, 4 Scenario 2 Input: {8, 3, 5, 1, 9} Output: 8 3 5 1 ... Read More

How to iterate over a 2D list (list of lists) in Java?

Deepti S
Updated on 18-Oct-2023 16:03:46

3K+ Views

A data structure known as a 2D list or list of lists can be utilised for saving a collection of data in a two-dimensional format. A row in the 2D list is represented by each inner list in this list of lists. A 2D list could be utilised, for instance, to store the data for a chessboard, where every component in the list corresponds to a single square on the board. Methods Used A 2D list can be iterated in one of the two methods that follow − Using Loops Using iterator Method 1: Employing Loops There are ... Read More

How to Iterate LinkedHashMap in Reverse Order in Java?

Deepti S
Updated on 18-Oct-2023 16:01:17

2K+ Views

The LinkedHashMap serves the purpose of maintaining the precise order of element addition. It elucidates the method for accessing elements in the sequence they were inserted. In addition to storing values based on their keys, the LinkedHashMap class expands upon the functionalities of the Hash Map class and implements the Map interface. It exclusively accommodates unique elements or mappings. It affords us the flexibility to utilize various data types, such as text, float, integer, etc., for assigning keys and values. By initially reversing the elements, we can alter the order of elements in the linked hash map. Subsequently, we can ... Read More

Golang program to implement a Trie data structure

Akhil Sharma
Updated on 18-Oct-2023 16:00:19

804 Views

A trie is a data structure like tree that is used to store and search a dynamic set of strings. It is useful while working with the data where keys share common prefix like dictionary words. Trie is different from the other retrieval data structures owing to its efficient string manipulation and retrieval properties. In this article we will learn to implement Trie data structure in Go programming language. Explanation The Trie, also known as a retrieval tree is a type of tree data structure that is commonly used for storing and managing collections of strings. It offers access, to ... Read More

Advertisements