java - How to differentiate String and Integer in ArrayList? -


i have array list this

arraylist list = new arraylist(); list.add("somethingold"); list.add(3); list.add("somethingnew"); list.add(5); 

now if print list output like:

[somethingold, 3, somethingnew, 5 ] 

here want fetch integer elements.

i want output like, if integer put in other list, else in 1 more list.

this want:

[3,5] [somethingold, somethingnew] 

have tried this?:

if(list.get(0) instanceof integer) {     // integer } else if (list.get(0) instanceof string) {     // string } 

looping through each element in list

for loop:

for (int = 0; < list.size(); i++) {    if (list.get(i) instanceof integer) {       // stuff    }    if (list.get(i) instanceof string) {       // stuff    } } 

for-each loop:

for (object obj: list) {    if (obj instanceof integer) {       // stuff    }    ... } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -