A Collection is a group of individual objects represented as a single unit. Java provides Collection Framework which defines several classes and interfaces to represent a group of objects as a single unit.
Input : List = [3, 5, 18, 4, 6] Output: Min value of our list : 3 max value of our list : 18 Input : List = ['a', 'a', 'a'] Output: All elements are equal
- Take inputs in the list.
- Create two variables, minimum and maximum.
- Use Collections.min() method and store the return value in min variable.
- Use Collections.max() method and store the return value in max variable.
- If the minimum and maximum variables are equal then print Equal elements.
- Else print minimum and maximum variables.
Below is the implementation of the above approach:
Min value of our list : 3 Max value of our list : 18
Time Complexity: O(N), where N is the length of the list.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.