日期:2014-05-20 浏览次数:20736 次
String[] ls={"A","B","C","V","G","H","K"};
String[] ses={"B","G","K"};
List<String> list1=new LinkedList<String>(Arrays.asList(ls));
List<String> list2=Arrays.asList(ses);
list1.removeAll(list2);//移除list1中存在的list2的元素
list1.addAll(0, list2);//再把这些元素放到首位
ls=list1.toArray(new String[list1.size()]);
System.out.println(Arrays.toString(ls));
public static void main(String[] args) {
String[] ls = { "A", "B", "C", "V", "G", "H", "K" };
String[] ses = { "B", "G", "K" };
sort(ls,ses);
}
private static void sort(String[] ls,String[] ses) {
Map<String,Integer> map = new LinkedHashMap<String,Integer>();
for (String s : ses) {
map.put(s, 0);
}
for (String s : ls) {
map.put(s, 1);
}
LinkedList<String> list = new LinkedList<String>();
for (String key : map.keySet()) {
if(map.get(key) > 0) list.add(key);
}
System.out.println(list);
}