Found 73 Articles for Campus Interview

Java Program to Sort ArrayList of Custom Objects by Property

AmitDiwan
Updated on 30-Mar-2022 07:40:55

583 Views

In this article, we will understand how to sort arrayList of custom objects by property. The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed.Array lists are created with an initial size. When this size is exceeded, the collection is automatically enlarged. When objects are removed, the array may be shrunk.Below is a demonstration of the same −Suppose our input is −The list is defined as Java Scala Python MysqlThe desired output would be −The list after sorting values: Java Mysql Python ScalaAlgorithmStep 1 - START Step 2 - Declare namely ... Read More

Java Program to Perform the inorder tree traversal

AmitDiwan
Updated on 30-Mar-2022 07:39:14

640 Views

In this article, we will understand how to perform the inorder tree traversal. In InOrder traversal, each node is processed between subtrees.In simpler words, visit left subtree, node and then right subtree.Below is a demonstration of the same −Suppose our input is −Run the programThe desired output would be −The In-Order traversal of the tree_object is: 5->12->6->1->9->AlgorithmStep 1 - START Step 2 - A class with the data specifications is previously defined. Step 3 - Create a new instance of the class. Step 4 - Initialize the instance with relevant values. Step 5 - Invoke the method to perform inorder ... Read More

Java Program to Sort a Map By Values

AmitDiwan
Updated on 30-Mar-2022 07:33:04

341 Views

In this article, we will understand how to sort a map by values. Java HashMap is a hash tablebased 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: Key = Java, Value = 45 Key = Scala, Value = 20 Key = Mysql, Value = 11 Key = Python, Value = 75The desired output would be −The HashMap after sorting is: Key = Mysql, Value = 11 Key = Scala, Value = 20 Key = Java, Value = 45 Key = Python, Value = 75AlgorithmStep ... Read More

Java Program to Merge two lists

AmitDiwan
Updated on 30-Mar-2022 07:32:25

353 Views

In this article, we will understand how to merge two lists. A list is an ordered collection that allows us to store and access elements sequentially. It contains the index-based methods to insert, update, delete and search the elements. It can also have the duplicate elements.Below is a demonstration of the same −Suppose our input is −First list: [45, 60, 95] Second list: [105, 120]The desired output would be −The list after merging the two lists: [45, 60, 95, 105, 120]AlgorithmStep 1 - START Step 2 - Declare three integer lists namely input_list_1, input_list_2 and result_list. Step 3 - Define ... Read More

Java Program to Initialize a List

AmitDiwan
Updated on 30-Mar-2022 07:24:34

635 Views

In this article, we will understand how to initialize a list. A list is an ordered collection that allows us to store and access elements sequentially. It contains the index-based methods to insert, update, delete and search the elements. It can also have the duplicate elements.Below is a demonstration of the same −Suppose our input is −Run the programThe desired output would be −Initializing an integer list The elements of the integer list are: [25, 60] Initializing a string list The elements of the string list are: [Java, Program]AlgorithmStep 1 - START Step 2 - Declare an integer list ... Read More

Java Program to Rotate Elements of a List

AmitDiwan
Updated on 30-Mar-2022 07:24:09

327 Views

In this article, we will understand how to rotate elements of a list. The List extends Collection and declares the behavior of a collection that stores a sequence of elements. The Collection is a framework that provides architecture to store and manipulate the group of objects. Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion.Below is a demonstration of the same −Suppose our input is −Input list: [100, 150, 200, 250, 300]The desired output would be −The list after one rotation: [150, 200, 250, 300, 100]AlgorithmStep 1 - ... Read More

Java Program To Find all the Subsets of a String

AmitDiwan
Updated on 30-Mar-2022 07:21:35

995 Views

In this article, we will understand how to find all the subsets of a string. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”). A part or a subset of string is called substring.Below is a demonstration of the same −Suppose our input is −The string is defined as: JVMThe desired output would be −The subsets of the string are: J JV JVM V VM MAlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Define the values. Step 4 - Initialize a temporary variable to increment after every iteration. ... Read More

Java Program to divide a string in 'N' equal parts

AmitDiwan
Updated on 30-Mar-2022 07:07:44

501 Views

In this article, we will understand how to divide a string in 'N' equal parts. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”).Below is a demonstration of the same −Suppose our input is −Input string: Java Program is fun!The desired output would be −The length of the string is: 20 4 equal parts of given string are Java Progr am is fun!AlgorithmStep 1 - START Step 2 - Declare a string namely input_string, two integers namely string_length and N. Step 3 - Define the values. Step 4 - Initiatize a temporary ... Read More

Java Program to Get Minimum and Maximum From a List

AmitDiwan
Updated on 30-Mar-2022 06:57:32

547 Views

In this article, we will understand how to get minimum and maximum from a list. A list is an ordered collection that allows us to store and access elements sequentially. It contains the index-based methods to insert, update, delete and search the elements. It can also have duplicate elements.Below is a demonstration of the same −Suppose our input is −Input list: [500, 650, 300, 250, 110]The desired output would be −The minimum value of the list is: 110 The maximum value of the list is: 650AlgorithmStep 1 - START Step 2 - Declare a list namely input_list. Step 3 - ... Read More

Java Program to Check if a String is Empty or Null

AmitDiwan
Updated on 30-Mar-2022 06:53:24

688 Views

In this article, we will understand how to check if a string is empty or null. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”).Below is a demonstration of the same −Suppose our input is −Input string: nullThe desired output would be −The string is a null stringAlgorithmStep 1 - START Step 2 - Declare a string namely input_string. Step 3 - Define the values. Step 4 - Using an if-loop, compute input_string == null. If true, the string is null, else the string is not null. Step 5 - Display the ... Read More

Advertisements