我有一個包含20個元素的列表,但它包含15位置的空值,如何從List
刪除空值?列表大小與它的大小不匹配
-2
A
回答
1
1
如果你不想讓「空」形象出現在列表上,只是這樣做:
for each item on a list
if item == null then continue
else
add an item to <List>Images
如果你傳遞一個空物體圖像的列表中,它仍然佔據放在列表中,即使這個地方在技術上未初始化。
1
你不能說null
值意味着對象不存在,即使null
不是java中的對象。
String s = null
表示未設置String s
的引用,但聲明已完成,該對象具有字符串類型並且被稱爲s。
看到關於它的更詳細,oracle doc: The Kinds of Types and Values
public static void main(String[] args)
{
ArrayList al = new ArrayList();
al.add(null);
al.add("not null");
System.out.println(al.size()); //output 2
//if you wanna know how many objects inside of list and isn't null
int count=0;
for(Object obj:al)
if(!(obj==null))
count++;
System.out.println(count); //output 1
System.out.println(al); //output [null, not null] ← null is exist.
}
所以在你的情況下,大小()的返回應該是20
相關問題
- 1. 大小不匹配
- 2. 列表大小匹配的html表格
- 3. 我的JFrame大小與設置的大小不匹配
- 4. UIWebView中的字體大小與iOS字體大小不匹配
- 5. 提交後Docker鏡像大小與容器大小不匹配
- 6. 等距立方體,大小與瓷磚大小不匹配128x128
- 7. Verilog - 端口大小與連接大小不匹配
- 8. python opencv VideoWriter:OpenCV:幀大小與視頻大小不匹配
- 9. Reportlab文本背景大小與字體大小不匹配
- 10. cuFFT R2C批量輸出大小與輸入大小不匹配
- 11. 字體大小不匹配
- 12. navigationBar.IntrinsicContentSize.height與實際欄大小不匹配
- 13. 錯誤:將光標更新到配對列表中:「TypeError:序列大小必須與行的大小匹配」
- 14. 模式匹配的特定大小或更大/更小的列表
- 15. DirectX 11:編碼的頂點着色器大小與指定大小不匹配
- 16. GZip頁腳中的流大小與實際流大小不匹配
- 17. 加密文件大小的計算與真實大小不匹配
- 18. 圖像大小使用imread和大小不匹配 - matlab
- 19. Windows窗體大小不匹配在屬性窗口大小
- 20. Django查詢不區分大小寫的列表匹配
- 21. 縮放以匹配大小
- 22. Torch7函數addmv的大小不匹配
- 23. Flash對象的大小不匹配上
- 24. movq的操作數大小不匹配
- 25. 不區分大小寫的匹配
- 26. 不區分大小寫的Rspec匹配
- 27. AlertDialog中不匹配的按鈕大小
- 28. 不匹配的XRef流條目大小
- 29. 的Javascript匹配 - 不區分大小寫
- 30. postgresql總數據庫大小不匹配單個表大小的總和
你可以發佈用於執行此操作的代碼嗎?然後我們可以就如何改變它提出建議。 –
非常不清楚的問題。你問如何從列表中刪除空元素? – shmosel