I am new to sorting in Java, scenario is i am having 8 balls, in that one ball is having less weight, by using java code i need to identify which one is having less weight.
I have used following code, but not sure, this will work in all scenarios:
public class SortingMarble {
public static void main(String[] args){
List<Integer> list = Arrays.asList(20, 30, 90, 50, 45, 100,65,90);
List<Integer> copy = new ArrayList<Integer>(list);
Integer smallest = Collections.min(copy); // 20
System.out.println(smallest);
}
}
Is there any java design pattern I can use here? is there any collection API to sort out this?
I have to use collections to sort out this. I used List Api, is there any other specific api in collection to sort?
Here i have given number, How can I make it to 8 different balls, where one ball is weighing less than the rest 7 balls?