List of usage examples for java.util Hashtable put
public synchronized V put(K key, V value)
From source file:Main.java
public static void main(String args[]) throws Exception { ServerSocket ssock = new ServerSocket(1234); Hashtable hash = new Hashtable(); hash.put("A", "a"); while (true) { Socket sock = ssock.accept(); ObjectOutputStream ostream = new ObjectOutputStream(sock.getOutputStream()); ostream.writeObject(hash);//from w ww. ja v a 2 s . c o m ostream.close(); sock.close(); } }
From source file:MainClass.java
public static void main(String[] s) { Hashtable table = new Hashtable(); table.put("key1", "value1"); table.put("key2", "value2"); table.put("key3", "value3"); Map m = Collections.unmodifiableMap(table); m.put("key3", "value3"); System.out.println(m);/*from ww w . j a v a 2s . c o m*/ }
From source file:MainClass.java
public static void main(String[] s) { Hashtable table = new Hashtable(); table.put("key1", "value1"); table.put("key2", "value2"); table.put("key3", "value3"); Enumeration e = table.elements(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); System.out.println(key + " : " + table.get(key)); }/* w w w .ja v a 2 s . c o m*/ System.out.println(table.values()); }
From source file:MainClass.java
public static void main(String[] s) { Hashtable table = new Hashtable(); table.put("key1", "value1"); table.put("key2", "value2"); table.put("key3", "value3"); Set set = table.entrySet();//ww w.jav a 2s. com Iterator it = set.iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); System.out.println(entry.getKey() + " : " + entry.getValue()); } }
From source file:MainClass.java
public static void main(String args[]) { Hashtable ht = new Hashtable(); ht.put("Tokyo", "Japan"); ht.put("Beijing", "China"); ht.put("Bangkok", "Thailand"); String city = "Beijing"; String country = (String) ht.get(city); if (country != null) System.out.println(city + " is located in " + country); else//from w w w . ja va 2 s. c o m System.out.println(city + " is not located in the hashtable"); }
From source file:MainClass.java
public static void main(String args[]) { Hashtable ht = new Hashtable(); ht.put("a", "a"); ht.put("b", new Double(2)); ht.put("c", "b"); ht.put("d", new Integer(30)); show(ht);//from w ww . j ava2 s .c o m }
From source file:Print.java
public static void main(String[] args) throws Exception { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:/tmp/marketing"); Context initCtx = new InitialContext(env); File f = (File) initCtx.lookup("reports/report1.txt"); if (f != null) { BufferedReader br = new BufferedReader(new FileReader(f)); String l = null;//from w ww . ja v a2 s . c om while ((l = br.readLine()) != null) System.out.println(l); } }
From source file:MainClass.java
public static void main(String args[]) { Hashtable hashtable = new Hashtable(); hashtable.put("apple", "red"); hashtable.put("strawberry", "red"); Enumeration e = hashtable.keys(); while (e.hasMoreElements()) { Object k = e.nextElement(); Object v = hashtable.get(k); System.out.println("key = " + k + "; value = " + v); }//from w ww . j av a 2 s .c o m }
From source file:Rename.java
public static void main(String[] args) throws Exception { String initialContextString = "/"; if (args.length < 2) { System.out.println("Useage: java Rename filename1 filename2"); System.exit(-1);// w ww . j a v a 2s. co m } Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:" + initialContextString); Context initCtx = new InitialContext(env); System.out.println("Renaming " + args[0] + " to " + args[1]); initCtx.rename(args[0], args[1]); }
From source file:Modify1Example.java
public static void main(String args[]) { Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample"); try {// ww w. j ava2 s . c o m DirContext dctx = new InitialDirContext(env); Attributes attrs = new BasicAttributes(true); attrs.put(new BasicAttribute("email", "name@site.com")); attrs.put(new BasicAttribute("website")); dctx.modifyAttributes("cn=Name, ou=People", DirContext.ADD_ATTRIBUTE, attrs); } catch (Exception e) { System.out.println(e); } }