title: [B cannot be cast to java.lang.String in LDAP Search
body: <p>When i am trying to search password of user from ldap server this
  below error displayed</p>
  
  <p>In this code its doesn't return user Password in String.  It throws</p>
  
  <pre><code>java.lang.ClassCastException: [B cannot be cast to java.lang.String 
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>public class selectEntry {
  
          DirContext ldapContext = null;
  
          public selectEntry() {
              try {
                  Hashtable&lt;String, String&gt; environment = new Hashtable&lt;String, String&gt;();
  
                  environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                  environment.put(Context.PROVIDER_URL, url);
                  environment.put(Context.SECURITY_AUTHENTICATION, conntype);
                  environment.put(Context.SECURITY_PRINCIPAL, AdminDn);
                  environment.put(Context.SECURITY_CREDENTIALS, password);
  
                  ldapContext = new InitialDirContext(environment);
  
                  System.out.println("Bind successful");
              } catch (Exception exception) {
                  exception.printStackTrace();
              }
          }
  
          public void getEntry() {
              try {
                  SearchControls searcCon = new SearchControls();
                  searcCon.setSearchScope(SearchControls.SUBTREE_SCOPE);
                  NamingEnumeration results
                          = ldapContext.search("uid=aruhat.aruhat,ou=openzki,dc=aruhat,dc=co,dc=in", "(uid=aruhat.aruhat)", searcCon);
                  if (results != null) {
                      while (results.hasMore()) {
                          SearchResult res = (SearchResult) results.next();
                          Attributes atbs = res.getAttributes();
                          Attribute atb = atbs.get("userPassword");
                          String name = (String) atb.get();
                         System.out.println("Name is :=&gt; " + name);
                      }
                  } else {
                      System.out.println("fail");
                  }
              } catch (Exception e) {
                  System.out.println("Exception Type:=&gt; "+e);
                  System.out.println("Exception Message:=&gt; "+e.getMessage());
                  e.printStackTrace();
              }
          }
  
          public static void main(String[] args) {
              new selectEntry().getEntry();
          }
      }
  </code></pre>
  
  <p></p>