![](/img/trans.png)
[英]How to convert an attribute ArrayList<String> or ArrayList<Integer> or ArrayList<MYCLASS> from a JSON object to a java object?
[英]To separate Integer and String ArrayList from Object ArrayList
我有一個包含對象的arraylist。 我有兩個不同的arraylist,一個包含字符串,另一個包含整數。 現在,我需要從父列表中獲取字符串和整數,並將其放入新的兩個arraylist中。 數組列表如下。
ArrayList<Object> lDeltaAttrList = new ArrayList<Object>();
ArrayList<String> lDeltaAttrListString = new ArrayList<String>();
ArrayList<Integer> lDeltaAttrListInteger = new ArrayList<Integer>();
請幫忙。
您只需檢查對象是字符串還是整數並將其放在正確的列表中即可。
for(Object o : lDeltaAttrList) {
if(o instanceof String) {
lDeltaAttrListString.add(o);
} else if(o instanceof Integer) {
lDeltaAttrListInteger.add(o);
}
}
用戶instanceof
關鍵字可檢查其是String對象還是Integer對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.