[英]How do you pass the elements from a one-dimensional array to a two dimensional array
[英]How do you create a two dimensional collection?
有沒有簡單的方法來創建二維集合?
二維集合實質上是在列表中包含列表。 例如,要創建字符串的二維數組列表,您可以執行以下操作:
ArrayList<ArrayList<String>> stringList = new ArrayList<ArrayList<String>>();
要添加新行,只需添加一個新的ArrayList即可:
stringList.add(new ArrayList<String>());
這是向第一行添加元素的方法:
stringList.get(0).add("example string");
2D集合有點抽象...您是什么意思? 雙輸入數組是2d集合。
為什么不使用Guava庫中的Multimaps? https://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained ,這些集合將jdk處理2D集合時缺少的所有內容都廣告化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.