Example usage for java.util Hashtable put

List of usage examples for java.util Hashtable put

Introduction

In this page you can find the example usage for java.util Hashtable put.

Prototype

public synchronized V put(K key, V value) 

Source Link

Document

Maps the specified key to the specified value in this hashtable.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] attrIDs = { "sn", "number", "value", "mail" };

    Attributes matchAttrs = new BasicAttributes(true);
    matchAttrs.put(new BasicAttribute("sn", "YourName"));
    matchAttrs.put(new BasicAttribute("mail"));

    Object obj = "yourObject";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "yourURL");

    DirContext ctx = new InitialDirContext(env);

    NamingEnumeration e = ctx.search("ou=People", matchAttrs, attrIDs);

    while (e.hasMore()) {
        SearchResult entry = (SearchResult) e.next();
        System.out.println(entry.getName());
    }//from w  ww.  j a  va  2 s  .  c  o  m
}

From source file:Main.java

public static void main(String[] args) {
    Hashtable<String, String> ht = new Hashtable<String, String>();

    ht.put("1", "One");
    ht.put("2", "Two");
    ht.put("3", "Three");

    Set st = ht.keySet();/*from   ww w  . j  a  v a  2  s.c o m*/

    Iterator itr = st.iterator();

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }
    st.remove("2");

    Enumeration e = ht.keys();
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "ldap://localhost/o=JNDITutorial";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "userDN");
    env.put(Context.SECURITY_CREDENTIALS, "secret");

    Control[] connectCtls = new Control[] { null };
    LdapContext ctx = new InitialLdapContext(env, null);

    Control[] ctxCtls = new Control[] { new SortControl(new String[] { "cn" }, Control.CRITICAL) };

    ctx.setRequestControls(ctxCtls);/*from w  w w. ja  v a  2s.c o m*/

    NamingEnumeration answer = ctx.list("");

    while (answer.hasMore()) {
        NameClassPair item = (NameClassPair) answer.next();
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "ldap://localhost/o=JNDITutorial";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "userDN");
    env.put(Context.SECURITY_CREDENTIALS, "secret");

    LdapContext ctx = new InitialLdapContext(env, null);

    NamingEnumeration answer = ctx.search("ou=People", "(cn=*)", null);

    System.out.println(ctx.getResponseControls());

    while (answer.hasMore()) {
        SearchResult si = (SearchResult) answer.next();
        if (si instanceof HasControls) {
            System.out.println(((HasControls) si).getControls());
        }//from ww  w. j av  a 2 s.  c  om
    }
    System.out.println(ctx.getResponseControls());
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    String title = (args.length == 0 ? "Sample Slider" : args[0]);
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JSlider js4 = new JSlider(JSlider.VERTICAL);
    Hashtable<Integer, JLabel> table = new Hashtable<Integer, JLabel>();
    table.put(0, new JLabel("O"));
    table.put(10, new JLabel("Ten"));
    table.put(25, new JLabel("Twenty-Five"));
    table.put(34, new JLabel("Thirty-Four"));
    table.put(52, new JLabel("Fifty-Two"));
    table.put(70, new JLabel("Seventy"));
    table.put(82, new JLabel("Eighty-Two"));
    table.put(100, new JLabel("100"));
    js4.setLabelTable(table);//from w  ww.j  av  a  2  s  . c om
    js4.setPaintLabels(true);
    js4.setSnapToTicks(true);
    frame.add(js4, BorderLayout.EAST);
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tick Slider");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSlider jSliderOne = new JSlider();

    jSliderOne.setPaintLabels(true);// www.  j  a v a2 s. c o m

    Hashtable<Integer, JLabel> table = new Hashtable<Integer, JLabel>();
    table.put(0, new JLabel(new ImageIcon("yourFile.gif")));
    table.put(10, new JLabel("Ten"));
    table.put(25, new JLabel("Twenty-Five"));
    table.put(34, new JLabel("Thirty-Four"));
    table.put(52, new JLabel("Fifty-Two"));
    table.put(70, new JLabel("Seventy"));
    table.put(82, new JLabel("Eighty-Two"));
    jSliderOne.setLabelTable(table);

    frame.add(jSliderOne, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Wrapper.class);
    Wrapper wrapper = new Wrapper();
    Hashtable<String, String> hashtable = new Hashtable<String, String>();
    hashtable.put("foo", "A");
    hashtable.put("bar", "B");
    wrapper.setHashtable(hashtable);//from   w w w .  j  av  a  2s  .co  m
    System.out.println(objectToXml(jc, wrapper));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "YourURL");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "userDN");
    env.put(Context.SECURITY_CREDENTIALS, "secret");
    EventContext ctx = (EventContext) (new InitialContext(env).lookup("ou=People"));

    NamingListener listener = new SampleNCListener();

    ctx.addNamingListener("cn=John", EventContext.ONELEVEL_SCOPE, listener);
}

From source file:DynamicUtilTreeNodeDemo.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
    Hashtable<String, Object> hashtable = new Hashtable<String, Object>();
    hashtable.put("Two", new String[] { "A", "B", "C" });

    Hashtable<Object, Object> innerHashtable = new Hashtable<Object, Object>();

    innerHashtable.put("Two", new String[] { "A", "B", "C" });

    hashtable.put("Three", innerHashtable);
    JTree.DynamicUtilTreeNode.createChildren(root, hashtable);
    JTree tree = new JTree(root);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);/*from  w  w  w  .j a v  a  2s . c om*/
    frame.setVisible(true);

}

From source file:PlanetDiameters.java

public static void main(String args[]) {
    String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" };
    float diameters[] = { 4800f, 12103.6f, 12756.3f, 6794f, 142984f, 120536f, 51118f, 49532f, 2274f };
    Hashtable hash = new Hashtable();
    for (int i = 0, n = names.length; i < n; i++) {
        hash.put(names[i], new Float(diameters[i]));
    }/*  ww w  .j a  v  a  2s. c  om*/
    Enumeration e = hash.keys();
    Object obj;
    while (e.hasMoreElements()) {
        obj = e.nextElement();
        System.out.println(obj + ": " + hash.get(obj));
    }
}