简体   繁体   English

如何列出Java属性对象中的所有值?

[英]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.

相关问题 java-如何打印请求对象的属性和值? - java - How do I print attributes and values of a request object? 如何使用BeanUtils内省获取Java对象的所有属性列表? - How to get the list of all attributes of a Java object using BeanUtils introspection? How do I remove all null and empty string values from an object in json java android from retrofit? - How do I remove all null and empty string values from an object in json java android from retrofit? 在以对象为值的Java哈希表中,如何返回对象值? - In a Java hashtable with objects as values, how do I return the object values? 如何在Java中对对象的属性进行排序 - How can I sort the attributes of an object in Java 如何在java中更改数组列表的所有值? - How can I change all values of an array list in java? ElasticSearch / Painless:如何访问/求和对象中的所有值 - ElasticSearch/Painless: How do I access/sum all values in an object Java - 如何从JList获取所有选定的值? - Java - How do I get a all the selected values from a JList? 如何在Java中显示数据库中的所有枚举值 - how do I show all enum values from database in Java 如何递归转储Java对象及其中对象的所有属性? - How do I dump all the properties of a Java object and of the objects in it recursively?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM