-1

我有一个包含对象的数组列表。我有两个不同的数组列表,一个包含字符串,另一个包含整数。现在我需要从父列表中获取字符串和整数并将其放入新的两个数组列表中。数组列表如下。

ArrayList<Object> lDeltaAttrList = new ArrayList<Object>();
ArrayList<String> lDeltaAttrListString = new ArrayList<String>();
ArrayList<Integer> lDeltaAttrListInteger = new ArrayList<Integer>();

请帮忙。

4

2 回答 2

4

您只需检查 Object 是 String 还是 Integer 并将其放入正确的列表中。

for(Object o : lDeltaAttrList) {
    if(o instanceof String) {
        lDeltaAttrListString.add(o);
    } else if(o instanceof Integer) {
        lDeltaAttrListInteger.add(o);
    }
}
于 2013-05-02T12:18:51.927 回答
0

用户instanceof关键字来检查它是 String 对象还是 Integer 对象。

于 2013-05-02T12:22:46.217 回答