2012-08-09 71 views
0

在以下代碼獲取ArrayList值?

queryCmisAdvance.getAdvanceKeywords()類AdvancePropertyKeywords

在類AdvancePropertyKeywords的返回的ArrayList

有三個參數String Property Name , condition and value.

一些時間是可能的值可以是「」(這是不爲空)

現在我想檢索屬性N ame的價值不是「」。

我的代碼

for(AdvancePropertyKeywords apk : queryCmisAdvance.getAdvanceKeywords()){ 

       if (apk.getValue()!="") { 
        System.out.println(apk.getPropertyName() +" " +apk.getCondition() + " "+apk.getValue()); 
       } 
      } 

輸出

From = 

SentOn > Wed Aug 22 12:00:00 UTC+2 2012 

EmailSubject LIKE folder 

DocumentTitle NULL rgftre 

CarbonCopy LIKE 

From value is "" 

SentOn value is Wed Aug 22 12:00:00 UTC+2 2012 

EmailSubject value is folder 

DocumentTitle value is rgftre 

CarbonCopy value is "" 
+1

什麼問題? – 2012-08-09 11:22:23

+4

不要將字符串與「!=」進行比較。使用.equals()。請參閱http://stackoverflow.com/questions/767372/java-string-equals-versus。 – 2012-08-09 11:22:54

回答

0

@DanGravell:謝謝,這個工程。

if (!(apk.getValue().equals(""))) { 
       System.out.println(apk.getPropertyName() +" " +apk.getCondition() + " "+apk.getValue()); 
} 
1

使用equals()方法,而不是!=運營商。 equals()方法比較對象內容,而==!=運營商在Object Comparision的情況下比較object reference values。見下面的代碼:

for(AdvancePropertyKeywords apk : queryCmisAdvance.getAdvanceKeywords()){ 
    if (!"".equals(apk.getValue()) { 
     System.out.println(apk.getPropertyName() +" " +apk.getCondition() + " "+apk.getValue()); 
    } 
} 
+0

我不必等於..我要感謝..我找到了解決方案。 – GameBuilder 2012-08-09 12:28:53