Last active
June 13, 2017 21:24
-
-
Save daejinseok/712702f1c7fa7f7e3d4cb41d6bf20bd3 to your computer and use it in GitHub Desktop.
Java Strong into HashSet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test_daejin; | |
import java.util.Arrays; | |
import java.util.HashSet; | |
import java.util.Iterator; | |
public class test_set { | |
// Java 1.4버전 String을 HashSet으로 변환 | |
public static HashSet strToSet( String s){ | |
return new HashSet(Arrays.asList(s.trim().split("\\s*,\\s*"))); | |
} | |
public static void main(String[] args) { | |
HashSet hs = strToSet(" 아빠, 엄마, 누나, 동생 "); | |
hs.add("아빠"); | |
hs.add("누나"); | |
Iterator i = hs.iterator(); | |
while(i.hasNext()){ | |
System.out.println( "|" + i.next() + "|"); | |
} | |
} | |
} | |
/* output | |
|누나| | |
|동생| | |
|아빠| | |
|엄마| | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment