Found 67 Articles for Campus Interview

Java Program to Join Two Lists

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

341 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

Aishwarya Naglot
Updated on 20-Aug-2025 12:26:31

452 Views

The Linked List in a Java is a data structure that is used for storing data in linear order. It has a series of node where each node contains two parts: data and a reference to the next node in the list. The first node is called the head and the last node is called the tail. In this article, we will learn how to access elements from a LinkedList in Java. Following are the ways to access elements from a LinkedList in Java: Using get() Method Using getFirst() Methods Using getLast() Method Accessing Elements from a LinkedList ... Read More

Java program to convert a list of string to comma separated string

Aishwarya Naglot
Updated on 26-Aug-2025 16:44:22

805 Views

A list is a collection in Java which is used for storing group of elements. It is an ordered collection which also allows to store duplicate elements. A String is a sequence of characters which is used for representing text in Java. Here, in this article, we are given a list of strings, we have to convert it into a comma-separated string in Java using different approaches. To understand this problem, consider the following input-output scenarios: Scenario 1 Input: ["Apple", "Banana", "Mango", "Orange"] Output: Apple, Banana, Mango, Orange Scenario 2 Input: ["Red", "Green", "Blue"] Output: ... Read More

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

Revathi Satya Kondra
Updated on 06-Jan-2025 22:46:56

295 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 the 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: 12345 The ... Read More

Java Program to Remove a Sublist from a List

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

418 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-Sep-2024 02:48:31

2K+ Views

In this article, we will understand how to iterate through each character of the string using Java. The string is a datatype that contains one or more characters and is enclosed in double quotes (“ ”). Char is a datatype that contains an alphabet an integer or a special character. Problem Statement Write a program to Iterate through each character of the string. Below is a demonstration of the same − Input The string is defined as: Java Program Output The characters in the string are: J, a, v, a, , P, r, o, g, r, a, m, Different approaches ... Read More

Java Program to Clear the StringBuffer

Shriansh Kumar
Updated on 16-Aug-2024 07:36:08

2K+ Views

On clearing the StringBuffer object, all the characters from the buffer will be removed. In this article, we will write Java program to clear the StringBuffer. StringBuffer is a peer class of String that provides much of the functionality of strings. But, String represents fixed-length, immutable character sequences while StringBuffer represents mutable character sequences. Example Scenario: Input: obj = Java Program Output: res = The result will be an empty StringBuffer object. Using delete() method The StringBuffer class of java.lang package provides a method named delete() to clear the StringBuffer. This method accepts start and end indices ... Read More

Java Program to Create random strings

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

746 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 27-Aug-2024 18:48:06

2K+ 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 index-based methods to insert, update, delete, and search the elements. It can also have duplicate elements. We will be using different approaches to split a list into two halves − Problem Statement Write a Java program to split a list into two halves. As demonstrated below − Input  Input list :[Java, Python, JavaScript, Shell, Scala] Output The first half of the list is: [Java, Python] The second half of ... Read More

Java Program to split into a number of sub-strings

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

674 Views

In this article, we will understand how to splitting into a number of sub-strings. 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 −Input string: JVMThe desired output would be −The substring list printed as an ArrayList : [J, JV, JVM, V, VM, M] The sub-strings after splitting is: (1) "J" (2) "JV" (3) "JVM" (4) "V" (5) "VM" (6) "M"AlgorithmStep 1 - START Step 2 - Declare a string namely ... Read More

Advertisements