Stack Problems

Stack is part of Collection in Java, it is a Interface which is based on Stack Data Structure. It follows the principle of LIFO that is Last in First Out.

Stack in Java

25. How to Add Elements in Stack Collection in Java?

Input: stack = [10, 20, 30, 40, 50]
            ele = 100 
            pos = 2
Output:  [10 , 20 , 100 , 30 , 40 , 50]
Explanation: Add element (ele) in the stack at the position (pos).

26. Calculate weight of parenthesis based on the given conditions.

Input: S = “(()(()))” 
Output: Explanation: 
() = 1 , then (()) =2 
()(()) = 1+2 = 3 
(()(())) = 2*3 = 6
To check the rules refer to the article mentioned below.

27. Check If it is Possible to Convert Binary String into Unary String

Choose two adjacent characters, such that both are 1’s or 0’s. Then invert them, Formally, if both are 0’s then into 1’s or vice-versa. 
If we are able to convert every element either to all 1 or all 0 then the answer will be Yes else No.
Input: N = 6, S = “110110”
Output: YES
Explanation: The operations are performed as:
                        Invert 0,1 ->  S = 000110
                        Invert 4,5 -> S = 000000

Java Collection Exercise

The Java Collection framework is a fundamental part of the Java programming language, It covers a major part of Java and acts as a prerequisite for many Advanced Java Topics. However, programmers often find it difficult to find a platform to Practice Java Online.

Take a look at our Java Collection Exercise that contains Java Collection Practice Problems to practice and to develop your Java Programming skills. Our Java Collection Practice Exercise will cover all the topics from Basic to Advanced, from ArrayList to Priority Queue. So, let’s dive in and sharpen our Java Collection skills together!

Table of Content

  • Basic Program
  • ArrayList Problems
  • LinkedList Problems
  • HashMap Problems
  • HashSet Problems
  • Stack Problems
  • Queue Problems
  • Priority Queue Problems

Similar Reads

What is Collection in Java?

Collection Framework in Java contains a Set of Interfaces and Classes to represent groups of objects as a Single Unit. In Java, the Collection interface (java.util.Collection) and Map interface (java.util.Map) are the two main “root” interfaces of Java collection classes....

Basic Program

Want to solidify your Java collection skills? Here’s your chance! Get hands-on with these basic practice programs in Java Collection. Work with common collections like ArrayLists and HashSets, all while strengthening your Java coding abilities....

ArrayList Problems

ArrayList is a Collection which is the implementation of Dynamic Array Data Structure....

LinkedList Problems

LinkedList Class is an implementation of the LinkedList data structure which is a linear data structure where the elements are not stored in contiguous locations and every element is a separate object with a data part and address part....

HashMap Problems

HashMap is the Class in Java Collection which is implemented based on Map Data Structure. It works on Key value pairs where we can store data in pairs , and can access based on Key values in Java....

HashSet Problems

Challenge your understanding of Java HashSets! This section dives into practical problems that test your ability to leverage the unique properties of HashSets. Solve these problems and solidify your grasp of this essential Java collection!...

Stack Problems

Stack is part of Collection in Java, it is a Interface which is based on Stack Data Structure. It follows the principle of LIFO that is Last in First Out....

Queue Problems

Queue is the part of Java Collection, it is an Interface based on Queue Data Structure. It follows the Principle of FIFO that is First In First Out....

Priority Queue Problems

Got the hang of Java collections? Time to test your skills! This section throws some priority queue problems your way. Practice putting elements in order, taking them out strategically, and mastering this awesome data structure in a fun way....

Conclusion

You’ve completed these Java collection exercises.  Now you can handle ArrayLists, HashSets, Priority Queues, and more with confidence.  Ready to push your skills further?  Revisit these exercises, experiment with your own ideas, and solidify your Java collection mastery!...