java 问题! String 去重
发布网友
发布时间:2022-05-03 07:38
我来回答
共3个回答
热心网友
时间:2023-10-14 16:41
最简单的:
List<String> strList = new ArrayList<String>();
for(String str_ : str){
if(!strList.contains(str_))System.out.print(str_);
strList.add(str_);
}
以上代码未运行过,但是应该可以滴
热心网友
时间:2023-10-14 16:42
import java.util.Set;
import java.util.TreeSet;
public class Test {
public static void main(String[] args) {
String fdbs = "java,java,oracle,script";
String[] str = fdbs.split(",");
Set<String> set = new TreeSet<String>();
for (int i = 0; i < str.length; i++) {
set.add(str[i]);
}
str = (String[]) set.toArray(new String[0]);
for (int i = 0; i < str.length; i++) {
System.out.println(str[i]);
}
}
}
热心网友
时间:2023-10-14 16:42
import java.util.Set;
import java.util.TreeSet;
public class Admin {
public static void main(String[] args) {
String fdbs = "java","java","oracle","script";
String[] str = fdbs.split(",");
Set set = new TreeSet();
for (int i = 0; i < str.length; i++) {
set.add(str[i]);
}
str = (String[]) set.toArray(new String[0]);
for (int i = 0; i < str.length; i++) {
System.out.println(str[i]);
}
}
}
热心网友
时间:2023-10-14 16:41
最简单的:
List<String> strList = new ArrayList<String>();
for(String str_ : str){
if(!strList.contains(str_))System.out.print(str_);
strList.add(str_);
}
以上代码未运行过,但是应该可以滴
热心网友
时间:2023-10-14 16:42
import java.util.Set;
import java.util.TreeSet;
public class Test {
public static void main(String[] args) {
String fdbs = "java,java,oracle,script";
String[] str = fdbs.split(",");
Set<String> set = new TreeSet<String>();
for (int i = 0; i < str.length; i++) {
set.add(str[i]);
}
str = (String[]) set.toArray(new String[0]);
for (int i = 0; i < str.length; i++) {
System.out.println(str[i]);
}
}
}
热心网友
时间:2023-10-14 16:42
import java.util.Set;
import java.util.TreeSet;
public class Admin {
public static void main(String[] args) {
String fdbs = "java","java","oracle","script";
String[] str = fdbs.split(",");
Set set = new TreeSet();
for (int i = 0; i < str.length; i++) {
set.add(str[i]);
}
str = (String[]) set.toArray(new String[0]);
for (int i = 0; i < str.length; i++) {
System.out.println(str[i]);
}
}
}