List of usage examples for java.util Hashtable Hashtable
Hashtable(Void dummy)
From source file:Main.java
public static void main(String args[]) { Hashtable<Integer, String> htable = new Hashtable<Integer, String>(10); // put values into the table htable.put(1, "A"); htable.put(2, "B"); htable.put(3, "C"); htable.put(4, "from java2s.com"); // check table content System.out.println("Hash table content: " + htable); // clear the table htable.clear();/*from ww w.j a v a2 s . c om*/ // check content after clear System.out.println("Hash table content after clear: " + htable); }
From source file:Main.java
public static void main(String[] args) { Hashtable h = new Hashtable(20); System.out.println(h.put("one", new Integer(1))); System.out.println(h.put("name", "A")); System.out.println(h.put("date", new Date())); System.out.println(h.put("one", new Integer(4))); Enumeration e = h.keys();/* w ww .j a va 2s . c o m*/ while (e.hasMoreElements()) System.out.println(e.nextElement()); e = h.elements(); while (e.hasMoreElements()) System.out.println(e.nextElement()); }
From source file:MainClass.java
public static void main(String[] args) { String data;/*from ww w . j av a2s. com*/ String msg; Hashtable h = new Hashtable(20); System.out.println(h.put("one", new Integer(1))); System.out.println(h.put("name", "A")); System.out.println(h.put("date", new Date())); System.out.println(h.put("one", new Integer(4))); Enumeration e = h.keys(); while (e.hasMoreElements()) System.out.println(e.nextElement()); e = h.elements(); while (e.hasMoreElements()) System.out.println(e.nextElement()); }
From source file:Modify2Example.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 {// w ww. jav a2s . c om DirContext dctx = new InitialDirContext(env); ModificationItem[] mods = new ModificationItem[3]; mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("department", "sales")); mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("quota", "$1")); mods[2] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("assistant")); dctx.modifyAttributes("cn=Name, ou=People", mods); } catch (Exception e) { System.out.println(e); } }
From source file:FilterExample.java
public static void main(String[] argc) throws Exception { 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"); DirContext dctx = new InitialDirContext(env); String filter = "(&(cn=E*)(account>1005))"; NamingEnumeration result = dctx.search("ou=People", filter, null); while (result.hasMore()) { SearchResult sr = (SearchResult) result.next(); System.out.println("Result = " + sr.getName()); }/*w w w. j a va2 s.c o m*/ }
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 {// www . ja v a2s . 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); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { Hashtable hash = new Hashtable(89); hash.put("one", "two"); hash.put("two", "three"); hash.put("three", "four"); hash.put("four", "five"); System.out.println(hash);/*w w w. j a va2 s .co m*/ System.out.println(hash.size()); Enumeration e = hash.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); System.out.println(key + " : " + hash.get(key)); } Set set = hash.entrySet(); Iterator it = set.iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); System.out.println(entry.getKey() + " : " + entry.getValue()); } }
From source file:SearchScopeExample.java
public static void main(String[] argc) { 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 {/*from ww w . ja va 2 s .com*/ DirContext dctx = new InitialDirContext(env); String filter = "(&(cn=S*)(account>1000))"; String[] attrIDs = { "cn", "email" }; SearchControls sc = new SearchControls(); sc.setReturningAttributes(attrIDs); sc.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration result = dctx.search("ou=People", filter, sc); while (result.hasMore()) { SearchResult sr = (SearchResult) result.next(); System.out.println("Result = " + sr.getName()); } } catch (NamingException e) { System.out.println(e); } }
From source file:SearchControlsExample.java
public static void main(String[] argc) throws Exception { 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"); DirContext dctx = new InitialDirContext(env); String filter = "(&(cn=S*)(account>1005))"; String[] attrIDs = { "cn", "email" }; SearchControls sc = new SearchControls(); sc.setReturningAttributes(attrIDs);// w ww .j a v a 2 s . co m NamingEnumeration result = dctx.search("ou=People", filter, sc); while (result.hasMore()) { SearchResult sr = (SearchResult) result.next(); System.out.println("Result = " + sr.getName()); } }
From source file:AttributeExample.java
public static void main(String[] argc) throws Exception { 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"); DirContext dctx = new InitialDirContext(env); Attributes attrs = new BasicAttributes(true); attrs.put(new BasicAttribute("email")); attrs.put(new BasicAttribute("website", "www.pri.com")); NamingEnumeration result = dctx.search("ou=People", attrs); while (result.hasMore()) { SearchResult sr = (SearchResult) result.next(); System.out.println("Result = " + sr.getName()); Attributes srchAttrs = sr.getAttributes(); NamingEnumeration attributes = srchAttrs.getAll(); while (attributes.hasMore()) { Attribute attr = (Attribute) attributes.next(); System.out.println("Attribute: " + attr.getID()); NamingEnumeration values = attr.getAll(); while (values.hasMore()) { Object value = values.next(); System.out.println("Value = " + value); }/*from w w w. j ava 2 s .c o m*/ } } }