显示他们这是我的计划,以消除串的重复单词,使用设置 工作正常删除重复元素的程序,但输出是不正确的顺序如何删除重复的单词串,并在相同的顺序
public class Remove_DuplicateIN_String {
public static void main(String a[]) throws IOException {
String a1;//=new String[200];
int i;
InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader in =new BufferedReader(reader);
System.out.println("Enter the String ");
a1=(in.readLine());
System.out.print(a1);
System.out.println("\n");
String words[]=new String[100];
words=a1.split(" ");
System.out.println(words.length);
Set<String> uniq=new HashSet<String>();
for(i=0;i<words.length;i++)
{
uniq.add(words[i]);
}
Iterator it=uniq.iterator();
while(it.hasNext())
{
System.out.print(it.next()+" ");
}
}
}
输入字符串 喜喜的世界问好一个
喜喜的世界问好一个
喜世界你好
我想为喜世界你好一个
https://stackoverflow.com/questions/10752753/java-set-retain-order这可能有助于 –