我在分配數組列表中的值時遇到一些困難。我的代碼是:將結果添加到數組列表
while (answer.hasMore()) {
SearchResult rslt = (SearchResult)answer.next();
Attributes attrs = rslt.getAttributes();
System.out.println();
if (attrs.get("department") != null && attrs.get("telephonenumber") != null) {
System.out.println(attrs.get("department") + " " + attrs.get("name") + " " +
attrs.get("Description") + " " + attrs.get("mail") + " " +
attrs.get("telephonenumber")+
attrs.get("samaccountname") + attrs.get("samaccountname"));
}
我想每一個attrs.get("department") + attrs.get("description")+ attrs.get("name")+attrs.get("mail")
的值賦給一個數組列表。
我想在開始時就確定:
String[] name = new String[100];
,並在while循環我試圖讀取name屬性,我試圖做的:
name = attrs.get("name");
但沒有奏效。任何人都可以幫忙
通過做的工作,你的意思是編譯失敗?我懷疑'attrs.get()'返回一個'String'? – hmjd 2012-02-22 21:05:38
'attrs.get(「name」);'返回一個字符串?您不能將字符串分配給字符串數組。你可能想要編輯你的問題來表明你真的想要做什麼,因爲將不同的屬性分配給同一個數組真的沒什麼意義。 – Perception 2012-02-22 21:05:42