Found 73 Articles for Campus Interview

Java Program to Join Two Lists

AmitDiwan
Updated on 29-Mar-2022 13:50:24

241 Views

In this article, we will understand how to join two lists. 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 −First list is defined as: [Java, Python] Second list: [Mysql, Redshift]The desired output would be −The list after joining two strings: [Java, Python, Mysql, Redshift]AlgorithmStep 1 - START Step 2 - Declare two lists ... Read More

Java Program to Access elements from a LinkedList

AmitDiwan
Updated on 29-Mar-2022 12:54:08

317 Views

In this article, we will understand how to access elements from a 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 −Input list: [Python, Java, Scala, Java, JavaScript]The desired output would be −The element at index 3 is: JavaAlgorithmStep 1 - START Step 2 - Declare a linked list namely input_list. Step 3 - Define the values. Step 4 - Using the built-in ... Read More

Java Program to Add Element at First and Last Position of a Linked list

AmitDiwan
Updated on 29-Mar-2022 12:41:13

262 Views

In this article, we will understand how to add element at first and last position of a 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 −Input list: [Java, Scalaa, C++]The desired output would be −The list after adding elements is: [JVA, Java, Scalaa, C++, Spark]AlgorithmStep 1 - START Step 2 - Declare a LinkedList namely input_list. Step 3 - Define the ... Read More

Java Program to Convert a List of String to Comma Separated String

AmitDiwan
Updated on 29-Mar-2022 13:27:46

500 Views

In this article, we will understand how to convert a list of string to comma separated string. 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 −Input list: [Java, Scala, Python]The desired output would be −The list with comma separated elements: Java, Scala, PythonAlgorithmStep 1 - START Step 2 - Declare a List namely input_list. Step 3 - Define the values. Step 4 - ... Read More

Java Program to Differentiate String == operator and equals() method

AmitDiwan
Updated on 29-Mar-2022 12:30:48

153 Views

In this article, we will understand how to differentiate == operator and equals() method in Java. The == (equal to) operator checks if the values of two operands are equal or not, if yes then condition becomes true.The equals() method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.Below is a demonstration of the same −Suppose our input is −The first string : abcde The second string: 12345The desired output would be −Using == ... Read More

Java Program to Remove a Sublist from a List

AmitDiwan
Updated on 29-Mar-2022 12:28:04

273 Views

In this article, we will understand how to remove a sub-list 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 the duplicate elements.Below is a demonstration of the same −Suppose our input is −Input list: [Java, Programming, Is, Fun]The desired output would be −The list after removing a sublist is: [Java, Programming]AlgorithmStep 1 - START Step 2 - Declare an AbstractList namely input_list. Step 3 - Add the values to the list. Step 4 ... Read More

Java Program to Iterate through each character of the string.

AmitDiwan
Updated on 29-Mar-2022 12:27:43

1K+ Views

In this article, we will understand how to iterate through each character of the string. String is a datatype that contains one or more characters and is enclosed in double quotes (“ ”). Char is a datatype that contains an alphabet or an integer or a special character.Below is a demonstration of the same −Suppose our input is −The string is defined as: Java ProgramThe desired output would be −The characters in the string are: J, a, v, a, , P, r, o, g, r, a, m, AlgorithmStep 1 - START Step 2 - Declare a string namely input_string, a ... Read More

Java Program to Clear the StringBuffer

AmitDiwan
Updated on 29-Mar-2022 12:21:28

1K+ Views

In this article, we will understand how to clear the StringBuffer. StringBuffer is a peer class of String that provides much of the functionality of strings. String represents fixed-length, immutable character sequences while StringBuffer represents growable and writable character sequences.Below is a demonstration of the same −Suppose our input is −This string buffer is defined as: Java Program The desired output would be −The string buffer after clearing:AlgorithmStep 1 - START Step 2 - Declare an object of StringBuffer namely string-buffer. Step 3 - Define the values. Step 4 - Call the inbuilt function .delete() and pass the values ... Read More

Java Program to Create random strings

AmitDiwan
Updated on 29-Mar-2022 12:18:27

590 Views

In this article, we will understand how to create random strings. 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 −The size of the string is defined as: 10The desired output would be −Random string: ink1n1dodvAlgorithmStep 1 - START Step 2 - Declare an integer namely string_size, a string namely alpha_numeric and an object of StringBuilder namely string_builder. Step 3 - Define the values. Step 4 - Iterate for 10 times usinf a for-loop, generate a random value using the function Math.random() ... Read More

Java Program to Split a list into Two Halves

AmitDiwan
Updated on 29-Mar-2022 12:13:11

1K+ Views

In this article, we will understand how to split a list into two halves. 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 :[Java, Python, JavaScript, Shell, Scala]The desired output would be −The first half of the list is: [Java, Python] The second half of the list is: [JavaScript, Shell, Scala]AlgorithmStep 1 - START Step 2 - Declare three array list namely input_list, ... Read More

Advertisements