java list用法,去除字符串数组中重复值

import java.util.Arrays; import java.util.List; import java.util.LinkedList; public class ArrayTest { public static List printMap1(String[] s) { List list = new LinkedList(); List list2 = Arrays.asList(s); list.addAll(list2); return list; } public static String[] array_unique(String[] a) { // array_unique List list = new LinkedList(); for(int i = 0; i < a.length; i++) { if(!list.contains(a[i])) { list.add(a[i]); } } return (String[])list.toArray(new String[list.size()]); } public static void main(String[] args) { String[] ar = {"dd","cc","ee","ff","gg","cc","ee"}; String[] s = array_unique(ar); for(String aa : s) { System.out.println(aa); } List list3 = printMap1(ar); for(Object o : list3) { System.out.println(o); } } }

你可能感兴趣的:(Java面试大全,list,java,string,import,object,class)