directory-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lécharny <elecha...@gmail.com>
Subject Re: Read Attribute with Multiple Values
Date Wed, 04 Mar 2015 13:19:56 GMT
Le 04/03/15 13:31, Syed Mudassir a écrit :
> Hi.
>    I am using apache directory api in my java program to interact with ldap server.
>    Upon performing successful search,  I am able to get the Entry object.
>    But the Entry object has a method getAttributes() which will return a 
> collection of Attribute.
>    If an Attribute contains multiple values, how can I fetch all those values?
>    Presently, I see only method get() which will fetch just the first value.
> -- 
You have to use the iterator(). The best way to do that is :

Attribute myAttribute = entry.get( "MyAttribute" );

for ( Value<?> value : myAttribute )
{
    // do what you need to do with your value
}

or :

Iterator<Value<?>> iterator = myAttribute.iterator();

while ( iterator.hasNext() )
{
    Value<?> value = iterator.next();
    // ...
}

which is a bit more verbose.

Mime
View raw message