提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
用于从字符串数组中删除重复值的哈希集。
import java.util.List; import java.util.Arrays; import java.util.HashSet;/**来自 n o w j a v a . c o m**/ import java.util.Set; import java.util.Collection; public class Main { public static void main(String[] args) { // create and display a List<String> String[] colors = {"red", "white", "blue", "green", "gray", "orange", "tan", "white", "cyan", "peach", "gray", "orange"}; List<String> list = Arrays.asList(colors); System.out.printf("List: %s%n", list); /* 来 自* nowjava - 时 代 Java */ // eliminate duplicates then print the unique values printNonDuplicates(list); } // create a Set from a Collection to eliminate duplicates private static void printNonDuplicates(Collection<String> values) { // create a HashSet Set<String> set =