62,615
社区成员
发帖
与我相关
我的任务
分享
import java.util.*;
public class TestRepeat {
public static void main(String[] args) {
String[] str = { "a", "e", "ee", "rr", "ce", "love", "you", "am", "sb",
"bs", "jj", "gg", "mm", "love", "a", "e", "tt", "yy" };
List list = new ArrayList();
Set set = new TreeSet();
set.addAll(java.util.Arrays.asList(str));
System.out.println(set);
}
}
int[] src = { 49, 76, 38, 13, 27, 38, 65, 97, 13 };
int[] temp = new int[src.length];
int count = 0;
for (int i = 0; i < src.length; i++) {
temp[count] = src[i];
for (int j = 0; j < count; j++) {
if (temp[j] == temp[count]) {
count--;
break;
}
}
count++;
}
int[] dest = new int[count];
System.arraycopy(temp, 0, dest, 0, count);
Arrays.sort(dest);
System.out.println(Arrays.toString(dest));
int[] src = { 49, 38, 65, 97, 76, 13, 27, 38, 13 };
int[] temp = new int[src.length];
int count = 0;
for (int i = 0; i < src.length; i++) {
temp[count] = src[i];
for (int j = 0; j < count; j++) {
if (temp[j] == temp[count]) {
count--;
break;
}
if (temp[j] > temp[count]) {
temp[count] = temp[j] ^ temp[count];
temp[j] = temp[j] ^ temp[count];
temp[count] = temp[j] ^ temp[count];
}
}
count++;
}
int[] dest = new int[count];
System.arraycopy(temp, 0, dest, 0, count);
System.out.println(Arrays.toString(dest));
public class TestRepeat
{
/**
* @param args
*/
public static void main(String[] args)
{
String[] str = { "a", "e", "ee", "rr", "ce", "love", "you", "am", "sb", "bs", "jj", "gg", "mm", "love", "a",
"e", "tt", "yy" };//定义一个数组
List list = new ArrayList();//new一个arralist
Set set = new HashSet();//new 一个hashset
set.addAll(java.util.Arrays.asList(str));//将数组转为list并存入set中,就可以去掉重复项了
for (java.util.Iterator it = set.iterator(); it.hasNext();)
{
list.add(it.next());//遍历set 将所有元素键入list中
}
java.util.Collections.sort(list); //对list进行快速排序
System.out.println(list);//打印结果
}