java - Simplest way to retrieve an int from a mongo result? -


i'm pulling int mongo cursor object so:

dbobject mapobj = cursor.next(); int autostart = (int) (double) (double) mapobj.get("autostart"); 

it seems strange have triple cast integer, there better way?

i think looking this:

dbobject mapobj = cursor.next(); int autostart = ((number) mapobj.get("autostart")).intvalue(); 

no conversion string , safe if value gets converted double or long (with potential loss of precision) original integer value. double, long , integer extend number.

hth rob


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -