java - Convert array list items to integer -


i have arraylist, arr. arraylist stores numbers strings. want convert arraylist integer type. how can that???

arraylist arr = new arraylist();  string a="mode set - in service", b="mode set - out of service";  if(line.contains(a) || line.contains(b)) {     stringtokenizer st = new stringtokenizer(line, ":mode set - out of service in service");     while(st.hasmoretokens()) {       arr.add(st.nexttoken());       } } 

since you're using untyped list arr, you'll need cast string before performing parseint:

list<integer> arrayofints = new arraylist<integer>(); (object str : arr) {    arrayofints.add(integer.parseint((string)str)); } 

i recommend define arr follows:

list<string> arr = new arraylist<string>(); 

that makes cast in conversion unnecessary.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -