Found 75 Articles for Campus Interview

Java Program to Get key from HashMap using the value

AmitDiwan
Updated on 30-Mar-2022 10:40:31

3K+ Views

In this article, we will understand how to get key from HashMap using the value. Java HashMap is a hash table based implementation of Java's Map interface. It is a collection of key-value pairs.Below is a demonstration of the same −Suppose our input is −Input HashMap: {Java=8, Scala=5, Python=15} Key: 8The desired output would be −The value of Key: 8 is JavaAlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Define the values. Step 4 - Create a HashMap of integer and string values and initialize elements in it using the ‘put’ method. Step 5 - Define ... Read More

Java Program to Remove duplicate elements from ArrayList

AmitDiwan
Updated on 30-Mar-2022 10:34:39

2K+ Views

In this article, we will understand how to remove duplicate elements from arrayList. The ArrayList class is a resizable array, which can be found in the java.util package. The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified.Below is a demonstration of the same −Suppose our input is −Input list : [150, 250, 300, 250, 500, 150, 600, 750, 300]The desired output would be −The list with no duplicates is: [150, 250, 300, 500, 600, 750]AlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Define the ... Read More

Java Program to Update value of HashMap using key

AmitDiwan
Updated on 30-Mar-2022 10:34:53

508 Views

In this article, we will understand how to update value of HashMap using key. Java HashMap is a hash table based implementation of Java's Map interface. It is a collection of key-value pairs.Below is a demonstration of the same −Suppose our input is −Input HashMap: {Java=1, Scala=2, Python=3}The desired output would be −The HashMap with the updated value is: {Java=1, Scala=12, Python=3}AlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Define the values. Step 4 – Create a hashmap of values and initialize elements in it using the ‘put’ method. Step 5 - Display the hashmap on ... Read More

Java Program to Iterate over a Set

AmitDiwan
Updated on 30-Mar-2022 10:29:47

928 Views

In this article, we will understand how to iterate over a set. A Set is a Collection that cannot contain duplicate elements. It models the mathematical set abstraction.The Set interface contains only methods inherited from Collection and adds the restriction that duplicate elements are prohibited.Below is a demonstration of the same −Suppose our input is −Input set: [Java, Scala, Mysql, Python]The desired output would be −Iterating over Set using for-each loop: Java, Scala, Mysql, PythonAlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Define the values. Step 4 - Create a hashset of values and initialize elements ... Read More

Java Program to Iterate over a HashMap

AmitDiwan
Updated on 30-Mar-2022 09:08:14

303 Views

In this article, we will understand how to iterate over a HashMap. Java HashMap is a hash table based implementation of Java's Map interface. It is a collection of key-value pairs.Below is a demonstration of the same −Suppose our input is −Input Hashmap: {Java=Enterprise, JavaScript=Frontend, Mysql=Backend, Python=ML/AI}The desired output would be −The keys of the Hashmap are: Java, JavaScript, Mysql, Python, The Values of the Hashmap are: Enterprise, Frontend, Backend, ML/AI, AlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Define the values. Step 4 - Create a hashmap of strings and initialize elements in it using ... Read More

Java Program to Convert the ArrayList into a string and vice versa

AmitDiwan
Updated on 30-Mar-2022 08:46:31

262 Views

In this article, we will understand how to convert the arrayList into a string and vice versa. The ArrayList class is a resizable array, which can be found in the java. util package. The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified.Below is a demonstration of the same −Suppose our input is −Input string: Java ProgramThe desired output would be −The array after conversion from string is: J a v a P r o g r a mAlgorithmStep 1 - START Step 2 - Declare namely Step 3 ... Read More

Java Program to Convert the LinkedList into an Array and vice versa

AmitDiwan
Updated on 30-Mar-2022 08:20:05

239 Views

In this article, we will understand how to convert the linked list into an array and vice versa. The java.util.LinkedList class operations perform we can expect for a doubly-linked list. Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.Below is a demonstration of the same −Suppose our input is −The list is defined as: [Java, Python, Scala, Mysql]The desired output would be −The result array is: Java Python Scala MysqlAlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Define the values. Step 4 ... Read More

Java Program to Get the middle element of LinkedList in a single iteration

AmitDiwan
Updated on 30-Mar-2022 08:13:49

130 Views

In this article, we will understand how to get the middle element of linkedList in a single iteration. The java.util.LinkedList class operations perform we can expect for a doubly-linked list. Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.Below is a demonstration of the same −Suppose our input is −Input linked list: 100 200 330The desired output would be −The middle element of the list is: 200AlgorithmStep 1 - START Step 2 - Declare a LinkedList namely input_list. Declare five node objects namely head, first_node, second_node, ... Read More

Java Program to Implement the queue data structure

AmitDiwan
Updated on 30-Mar-2022 08:01:28

2K+ Views

In this article, we will understand how to implement the queue data structure. A Queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out (FIFO).Below is a demonstration of the same −Suppose our input is −Input Queue: [150, 300, 450, 600]The desired output would be −After removing an element, the elements of the queue are: [300, 450, 600]AlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Add elements to it using the ‘offer’ method. Step 4 - Display the queue content Step 5 - ... Read More

Java Program to Implement LinkedList

AmitDiwan
Updated on 30-Mar-2022 07:50:48

322 Views

In this article, we will understand how to implement linked-list. The java.util.LinkedList class operations perform we can expect for a doubly-linked list. Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.Below is a demonstration of the same −Suppose our input is −Run the programThe desired output would be −The elements of the linked list are: 100 150 200 250AlgorithmStep 1 - START Step 2 - Create a class with the required members. Step 3 - Define an ‘insert’ function to add elements to the list. Step ... Read More

Advertisements