java - How to store group member in string Array -


  • i able result while executing following code want store member of group in string array not it. new java can 1 me.
  • the following code

    system.out.println(" person common name = " + attributes.get("member")+"\t");

    is able give me group member want store in string array.

thanks in advance.

  package com.ankit.ldap;    import javax.naming.context;   import javax.naming.namingenumeration;   import javax.naming.directory.*;   import java.util.hashtable;    /**    * user: gmc    * date: 16/02/11    */   public class simplequery {        public static void main(string[] args) {           string username = "xxxxxxxxxxxxxxxxx";           hashtable env = new hashtable();           env.put(context.initial_context_factory, "com.sun.jndi.ldap.ldapctxfactory");           env.put(context.provider_url, "xxxxxxxxxxxxxxx");           env.put(context.security_authentication, "simple");           env.put(context.security_principal, new string(username));           env.put(context.security_credentials, "xxxxxx");            dircontext ctx = null;           namingenumeration results = null;           try {               ctx = new initialdircontext(env);               searchcontrols controls = new searchcontrols();               controls.setsearchscope(searchcontrols.subtree_scope);               results = ctx.search("", "(cn=competencygroup)", controls);               while (results.hasmore()) {                   searchresult searchresult = (searchresult) results.next();                   attributes attributes = searchresult.getattributes();                   attribute attr = attributes.get("cn");                   string cn = (string) attr.get();                     system.out.println(" person common name = " + attributes.get("member")+"\t");                     system.out.println(" person display name = " + attributes.get("displayname"));                      system.out.println(" person memberof = " + attributes.get("memberof"));               }           } catch (throwable e) {               e.printstacktrace();           } {               if (results != null) {                   try {                       results.close();                   } catch (exception e) {                   }               }               if (ctx != null) {                   try {                       ctx.close();                   } catch (exception e) {                   }               }           }       }   } 

if want store array of strings without knowing number of strings store use arraylist.

//create arraylist arraylist<string> membernames = new arraylist<string>(); // add memeber name array membernames.add(attributes.get("member")); 

Comments