Archives: Logical Programs

Merge two sorted ArrayLists

Problem Statement: Write a Java program to implement a function to merge two sorted ArrayLists into a single sorted ArrayList. Here’s a Java program that implements a function to merge two sorted ArrayLists into a single sorted ArrayList. OUTPUT: List 1: [2, 5, 8]List 2: [3, 4, 9]Merged List: [2, 3, 4, 5, 8, 9] …

Merge two sorted ArrayLists Read More »

Remove elements with Condition: preserve the original order

Problem Statement: Write a Java program to remove duplicates from an ArrayList while preserving the original order. Here’s a Java program that demonstrates how to remove duplicates from an ArrayList while preserving the original order. I’ll provide an explanation of the program’s logic. OUTPUT: Original List: [10, 20, 30, 20, 40, 10]List after removing duplicates: …

Remove elements with Condition: preserve the original order Read More »

List to Array Conversion

Problem Statement: Write a Java program to Convert an ArrayList of strings into a string array. Here’s a Java program that demonstrates how to convert an ArrayList of strings into a string array. I’ll provide an explanation of the program’s logic. OUTPUT: String Array:HelloWorldJavaProgramming Explanation: The toArray() method converts the ArrayList of strings into a …

List to Array Conversion Read More »

Create a stack using an ArrayList

Problem Statement: Create a stack using an ArrayList and implement push, pop, and peek operations. Here’s a Java program that demonstrates how to create a stack using an ArrayList and implements the push, pop, and peek operations. I’ll provide an explanation of the program’s logic. OUTPUT: Peek: 30Stack size: 3Pop: 30Pop: 20Is stack empty? false …

Create a stack using an ArrayList Read More »