To separate Integer and String ArrayList from Object ArrayList

I have an arraylist containing Objects. I have two different arraylists, one containing strings and the other integers. Now I need to get the strings and integers rom the parent list and put it in the new two arraylists. The arraylists are as follows.

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

Please help.

Answers


You simply check if the Object is whether a String or an Integer and put it in the right list.

for(Object o : lDeltaAttrList) {
    if(o instanceof String) {
        lDeltaAttrListString.add(o);
    } else if(o instanceof Integer) {
        lDeltaAttrListInteger.add(o);
    }
}

Need Your Help

Can you ever have too many “protected virtual” methods?

c# .net virtual protected

Here's a question for those of you with experience in larger projects and API/framework design.

Objective-C, changing NSButton functionality?

objective-c cocoa nsbutton

How can I change the functionality of a button that I used previously? For example, If I had a button that did "Proceed/Cancel" and let's say you "Proceed" the button would change to something such...

Binding an xml node's children to ASP.Net DropDownList

c# asp.net xml data-binding drop-down-menu

I'm trying to bind the contents of a node of XML to a Drop Down List without much success.