Write down the output of the following code. import java.util.HashSet; public class Main { public static void main(String[] args) { HashSet<String> cars = new HashSet<String>(); cars.add("Volvo"); cars.add("BMW"); cars.add("Ford"); cars.add("BMW"); System.out.println(cars); } }
时间: 2024-02-26 07:54:32 浏览: 47
The output of the code will be:
[Volvo, BMW, Ford]
Since a HashSet does not allow duplicate elements, the second "BMW" that is added to the set will not be added again.
阅读全文