java_Hashtable和Enumeration用法

  • Post author:
  • Post category:java






public static void main(String arg0[])

{

Hashtable hash=new Hashtable();

hash.put( “abc”,”1″);

hash.put(“ddd”,”1″);

hash.put( “asdf”,”2″);

Enumeration enumkey = hash.keys() ;

while(enumkey.hasMoreElements()){


String str=(String)enumkey.nextElement();

System.out.println(“——–“+str);

System.out.println(“=========”+hash.get( str));

if(“1”.equals(hash.get( str)))

hash.remove( str);

}

System.out.println(“-ssssssssssssssssssss-“+hash.get( “asdf”));

enumkey = hash.keys() ;

while(enumkey.hasMoreElements()){


String str=(String)enumkey.nextElement();

System.out.println(“——–“+str);

System.out.println(“=========”+hash.get( str));

}

}

public static void main(String arg0[])

{

Hashtable hash=new Hashtable();

hash.put( “abc”,”1″);

hash.put(“ddd”,”1″);

hash.put( “asdf”,”2″);

Enumeration enumkey = hash.keys() ;

while(enumkey.hasMoreElements()){


String str=(String)enumkey.nextElement();

System.out.println(“——–“+str);

System.out.println(“=========”+hash.get( str));

if(“1”.equals(hash.get( str)))

hash.remove( str);

}

System.out.println(“-ssssssssssssssssssss-“+hash.get( “asdf”));

enumkey = hash.keys() ;

while(enumkey.hasMoreElements()){


String str=(String)enumkey.nextElement();

System.out.println(“——–“+str);

System.out.println(“=========”+hash.get( str));

}

}