[英]How Do I List All the Values in a Java Attributes Object?
I know there is a simple answer but I can't seem to find it anywhere. 我知道有一个简单的答案,但我似乎在任何地方都找不到。
Below is a small snippet of code. 以下是一小段代码。 Can someone tell me how to list all the attributes and their associated values for the rsa object?
有人可以告诉我如何列出rsa对象的所有属性及其关联的值吗?
Thanks in advance, 提前致谢,
NamingEnumeration answer = executeSearch(context,env,sBaseDN);
while (answer.hasMore()) { // For each ou
SearchResult sr = (SearchResult) answer.next();
Attributes rsa = sr.getAttributes();
// How do I list all the attributes that were returned?
You can get the collection of NamingEnumerations by calling the getAll()
method of Attributes and then iterate over this collection to get attributes values, like: 您可以通过调用Attributes的
getAll()
方法来获取NamingEnumerations的集合,然后对该集合进行迭代以获取属性值,例如:
try {
for (NamingEnumeration attr = rsa.getAll(); attr.hasMore();) {
Attribute attribute= (Attribute) attr.next();
System.out.println("Attribute id: " + attribute.getID());
for (NamingEnumeration val = attribute.getAll(); val.hasMore();){
System.out.println("Attribute value: " + val.next());
}
}
} catch (NamingException e) {
e.printStackTrace();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.