How to create empty list using Collections class
package com.java2novice.collections;
import java.util.Collections;
import java.util.List;
public class MyEmptyList
{
public static void main(String a[])
{
List
myEmptyList = Collections.emptyList();
System.out.println("Empty
list: "+myEmptyList);
}
}
How to create empty set using Collections class
package com.java2novice.collections;
import java.util.Collections;
import java.util.Set;
public class MyEmptySet
{
public static void main(String a[])
{
Set
myEmptySet = Collections.emptySet();
System.out.println("Empty
set: "+myEmptySet);
}
}
How to create empty map using Collections class
package com.java2novice.collections;
import java.util.Collections;
import java.util.Map;
public class MyEmptyMap
{
public static void main(String a[])
{
Map myEmptyMap = Collections.emptyMap();
System.out.println("Empty
map: "+myEmptyMap);
}
}
How to Enumeration for Array List object
package com.java2novice.collections;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
public class MyListEnumeration
{
public static void main(String a[])
{
List
ls = new ArrayList();
ls.add("one");
ls.add("two");
ls.add("three");
ls.add("four");
Enumeration
enm = Collections.enumeration(ls);
while(enm.hasMoreElements())
{
System.out.println(enm.nextElement());
}
}
}
No comments:
Post a Comment