我試圖從輸入中刪除重複項。有很多方法可以做到這一點,使用ArrayList,LinkedList,哈希設置等。我知道如何做到這一點,如果輸入是作爲說{蘋果「,」球「,」蘋果「,」貓「},指定在問題中。 但我想用掃描儀類和輸入說一行,並希望刪除字符中的重複項,或刪除重複的單詞。你有一個簡單的方法來做到這一點。 我已經包含了我的早期方案的工作代碼。刪除用戶輸入的重複單詞或字符
public static void main(String[] args) {
// TODO code application logic here
Scanner scan= new Scanner(System.in);
String[] str= {"a", "b", "c", "a"};
System.out.println("enter text");
List<String> l=
Arrays.asList(str);
System.out.println(l);
Set<String> set= new HashSet<String>(l);
System.out.println(set);
}
有*應*是一個簡單的方法..檢查AVB Java數據結構 – Coffee 2013-02-19 00:00:16
什麼是「AVB」是什麼意思? - 新手 – user2085145 2013-02-19 03:35:37
- 可用。雅我knoooooow – Coffee 2013-02-19 15:04:12