2015-11-24 19 views
1

我需要檢查字節列表是否爲空? 列表b =字節;
繼碼盤是正確的如何比較java中的空Bytelist

 

    if(b == "[]") 
    { 
    SOP("empty") 
    } 

+0

......我沒有看到一個問題,除非你打算在那裏放一個問號而忘了。 –

+0

如果有任何滿足您的問題,請不要忘記將回答標記爲正確。 –

回答

1

使用isEmpty()。您目前正在比較List b與String[],而不是檢查List是否爲空。

if (b.isEmpty()) { 
    System.out.println("Empty"); 
} 
3

您正在檢查列表是否與字符串相同。也許這會有所幫助。

import java.util.ArrayList; 

class Main { 
    public static void main(String[] args) { 
     byte[] b = new byte[]{}; 
     ArrayList<Byte> b2 = new ArrayList<Byte>(); 

     if (b.length == 0) { 
      System.out.println("b is empty"); 
     } 
     if (b2.isEmpty()) { 
      System.out.println("b2 is empty"); 
     } 
    } 
}