package tw.xxx.myfirstproject.game;
import java.util.*;
public class GamePolymorphismDetial {
static Set tokenSet(String line){//輸入進一個字串line
String[] tokens = line.split(" ");//用空格區分line中的每個元素,將元素加入陣列tokens
return new HashSet(Arrays.asList(tokens));}//把陣列元素存進set中,因為set有不重複的特性,所以重覆者被刪
//asList(T... a)
//Returns a fixed-size list backed by the specified array.(list也是一個collection)
//HashSet(Collection<? extends E> c)
//Constructs a new set containing the elements in the specified collection.
public static void main(String[] args) {
System.out.println(tokenSet("the The the III I I iii"));
}
}
[the, The, III, iii, I]
留言列表