Campus Interview Articles

Found 34 articles

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

Aishwarya Naglot
Aishwarya Naglot
Updated on 26-Aug-2025 961 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 Interchange the Diagonals

Manisha Chand
Manisha Chand
Updated on 22-Aug-2025 423 Views

In this article, we will understand how to interchange the diagonal elements of a given matrix in Java. A matrix is a two-dimensional array made up of rows and columns. A matrix with m rows and n columns is called an m × n matrix. Each element in the matrix is represented by a[i][j], which means that the particular element a is present in the i-th row and j-th column. Problem Statement Write a Java program to interchange the elements of the primary and secondary diagonals of a square matrix. Example Scenario ...

Read More

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

Aishwarya Naglot
Aishwarya Naglot
Updated on 04-Aug-2025 324 Views

The java.util.LinkedList class represents a linked list in Java, specifically a doubly-linked list, i.e., we can traverse through the list either from the beginning or from the end, whichever is closer to the specified index. We can create and perform various operations on a linked list using the methods provided by this class.Retrieving the Middle Element of a LinkedList  In this article, we will understand how to find the middle element of a LinkedList using Java. We will use the following ways to do so: Using a While Loop Using size() ...

Read More

Java Program to Check if a set is the subset of another set

Aishwarya Naglot
Aishwarya Naglot
Updated on 18-Jun-2025 1K+ Views

In this article, we will understand how to check if a Set is a subset of another 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 not allowed. Following are the ways to check if a set is a subset of another set: Using containsAll() Method Using Stream API Using containsAll() Method In Java, the set interface has a method called containsAll() that checks ...

Read More

Java Program to Pass ArrayList as the function argument

Aishwarya Naglot
Aishwarya Naglot
Updated on 18-Jun-2025 4K+ Views

The ArrayList is a resizable array, which is part of 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. In this article, we will understand how to pass an ArrayList as a function argument. Following are the ways to pass an ArrayList as a function argument: Using Function Argument Using Return Type Using Function Argument We can pass an ArrayList as a function argument in Java. The function can take an ArrayList as a parameter and perform operations ...

Read More

Java Program to Convert the local Time to GMT

Aishwarya Naglot
Aishwarya Naglot
Updated on 18-Jun-2025 3K+ Views

In this article, we will learn how to convert the local time to GMT (Greenwich Mean Time) in Java. We need this conversion when we want to standardize time across different time zones or when working with systems that require GMT. We will cover the following methods to convert local time to GMT: Using ZonedDateTime class Using Calendar Class Using Date Class Using ZonedDateTime Class ZonedDateTime class was introduced in Java 8, which is used for converting local time to GMT. We can use the ...

Read More

Java program to detect loop in a LinkedList

Aishwarya Naglot
Aishwarya Naglot
Updated on 18-Jun-2025 623 Views

What is a LinkedList? A Linked list is a sequence of data structures where each node contains two parts as follows - Data: The value or information stored in the node. Next: A reference (or pointer) to the next node in the sequence. Detecting a Loop in a LinkedList A loop or cycle means that the last node of a linked list is connected back to one of the nodes earlier in the list, creating a cycle. Or, the next pointer of a node points to itself. The following are the ways ...

Read More

Java Program to Iterate over ArrayList using Lambda Expression

Aishwarya Naglot
Aishwarya Naglot
Updated on 10-Jun-2025 3K+ Views

The ArrayList class is a resizable array that can be found in 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. Lambda Expression is a feature that was introduced in Java 8. It is useful when we use collections, such as ArrayList, Set, or Map, and we want to perform operations on the elements of these collections. In this article, we will learn how to iterate over an ArrayList using a lambda expression in Java. Iterating Over an ArrayList Using Lambda Expressions There are two main ...

Read More

Java program to replace a character at a specific index

Aishwarya Naglot
Aishwarya Naglot
Updated on 30-May-2025 5K+ Views

In this article, we'll learn how to replace a character at a specific index in a string. Strings in Java are sequences of characters enclosed in double-quotes (" "). We use strings to represent text in our programs. Problem Statement You are given a string, an index, and a character. Your task is to replace the character at the specified index in the string with the new character. Input string: Java Programming, Index: 6 Output: Java P%ogramming Different Approaches There are multiple ways to achieve this in Java. Below are two common approaches: Using substring() ...

Read More

Java Program to Add Two Matrix Using Multi-Dimensional Arrays

Shriansh Kumar
Shriansh Kumar
Updated on 30-May-2025 2K+ Views

For two given matrices, each of size m x n, we need to write a Java program to add them. Amatrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m x n matrix. Individual entries in the matrix are called elements and can be represented by a[i][j], which means that the element a is present at the ith row and jth column. Matrix is an example of multi-dimensional array. In Java, a multi-dimensional array is an array of arrays. It is used to store data within a ...

Read More
Showing 1–10 of 34 articles
« Prev 1 2 3 4 Next »
Advertisements