-
자바(2)Data/Container 2016. 5. 6. 18:37
import java.util.*;
class Collections03 {
public static void main(String[] args) {
List list = new ArrayList();
list.add("하나");
list.add(2);
...
System.out.println(list);
Iterator elements=list.iterator();
while(elements.hasNext()) {
... elements.next() ...
}
/* or
for(int i=0; i<list.size(); i++) {
... list.get(i) ...
}*/
}
}
[하나, 2, ... ]
-
import java.util.*;
class Collections07 {
public static void main(String[] args) {
String[] fruitNames = { "Apple", "banana", ... };
Vector<String> list = new Vector<String>();
for(String name : fruitNames) { list.add(name); }
/* or
for(int i=0; i < fruitNames.length; i++) { list.add(fruitNames[i]); }
*/
for(String temp : list) { // JDK 5.0
... temp ...
}
/* or
for(int j=0; j < list.size(); j++) {
... list.get(j) ...
}
*/
}
}
-
import java.util.*;
public class EnumerationTest01 {
public static void main(String[] args){
Vector vec = new Vector();
list.add("하나");
list.add(2);
...
Enumeration enu = vec.elements();
while( enu.hasMoreElements()) {
... enu.nextElement() ...
}
}
}
-
import java.util.*;
class HashMapEx1
{
public static void main(String[] args)
{
HashMap map = new HashMap();
map.put("castello", "1234");
map.put("asdf", "1111");
...
System.out.println(map);
... map.get("asdf") ...
}
}
{ ..., asdf=1111, castello=1234, ... }
-
import java.util.*;
class HashTableTest {
public static void main(String[] args) {
Hashtable ht = new Hashtable();
ht.put("사과", "Apple");
ht.put("딸기", "StrawBerry");
...
System.out.println(ht);
String Val = (String)ht.get("포도");
if(Val != null) { ... }
Enumeration Enum = ht.keys();
while(Enum.hasMoreElements()){
Object k = Enum.nextElement();
Object v = ht.get(k);
...
}
}
}
{딸기=StrawBerry, 사과=Apple, ... }