Found 34494 Articles for Programming

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

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

512 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?

Deepti S
Updated on 18-Oct-2023 16:25:59

1K+ Views

With the help of the AbstractMap Class, Java's TreeMap implements the Map interface and NavigableMap. This map is sorted using either the keys' inherent ordering or a Comparator that was provided when the map was created. When working with a TreeMap in Java, the objective is to iterate via its elements. However, due to TreeMap not being a Collection, we cannot directly iterate over it using iterators. Methods Used To iterate through a TreeMap in Java, we need to utilize the TreeMap.entrySet() method. This function gives back a collection-view (SetMap.Entry>) of all the mappings that were saved in the TreeMap. ... Read More

How to Iterate HashMap in Java?

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

199 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?

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

642 Views

The Java HashSet class employs a hash table internally to implement the Set interface, which uses a HashMap instance. The class does not guarantee that the items will remain the same over time because the iteration order of the factors within the hash set is not always guaranteed. Null elements may be included in this class. The hash function provides efficient performance for fundamental operations like add, delete, contains, and size, assuming it effectively distributes the elements through the buckets. The Set interface is implemented by HashSet, which extends AbstractSet. It creates a collection using the hashing technique and saves ... Read More

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

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

1K+ 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

721 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

364 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

Go Language Program to Implement Floyd's Triangle

Akhil Sharma
Updated on 18-Oct-2023 15:58:27

83 Views

Floyd's Triangle is a right-angled triangular pattern of numbers, named after the renowned American computer scientist Robert W. Floyd. Using sequences of natural integers starting at 1 and increasing by 1 in each row, we build this triangle. In this article, we are going to implement Floyd's Triangle in go, implementation here means we are going to create floyd's triangle and then print it. Explanation Floyd's Triangle, much like Pascal's Triangle, is a triangular arrangement of the natural numbers with a right angle. There is progression of numbers from left to right across the table, starting at 1 in each ... Read More

Go Language Program to Convert Decimal to Roman Numerals

Akhil Sharma
Updated on 18-Oct-2023 15:55:07

222 Views

Roman numerals are an ancient numerical system that has found its way into modern applications like clock faces, book chapters, and movie credits. In this article, we are going to Convert Decimal to Roman Numerals. We will look at two different examples, in the first example we will use the recursive approach and in the second example we are going to use the iterative approach. Explanation Roman numerals have been one of the languages to express the marvel of Mathematics. Clock faces, book chapters, and movie credits are just some of the current uses for the old Roman number system. ... Read More

Show Normal Inverse Gaussian Distribution in Statistics using Python

Nikitasha Shrivastava
Updated on 18-Oct-2023 15:43:03

145 Views

In this article we will be discussing the Normal inverse Gaussian distribution and also discuss how to implement and show this distribution using Python. Understanding the Problem The Normal Inverse Gaussian distribution in statistics is the probability distribution which can be used in various fields like finance, risk management and statistical analysis. So we will discuss the logic behind this distribution to implement in Python. Logic for The Above Problem The normal-inverse Gaussian distribution (NIG), a continuous probability distribution, is characterized as the normal variance-mean mixture with the inverse Gaussian distribution as the mixing density. To plot and show the ... Read More

Advertisements