java - How do I use ArrayList<Integer>#contains when I only have a BigInteger? -


i pulling data values database returns list of <integer>. however, see if list contains biginteger. there simple way this?

i have following code in java:

arraylist<integer> arr = new arraylist<integer>() {{add(new integer(29415));}};  boolean contains = arr.contains(29415); // true boolean contains2 = arr.contains(new biginteger("29415")); // false 

i'm not sure on efficient way this?

the correct answer returned evaluation of following:

val != null    && biginteger.valueof(integer.min_value).compareto(val) < 0    && biginteger.valueof(integer.max_value).compareto(val) > 0    && list.contains(val.intvalue()) 

this correctly solve question of whether biginteger have "contained" within list<integer>. note here downcast necessary. if val outside range of integer values there no need downcast know value cannot within list.

a more relevant question whether should using list<biginteger> in place of list<integer> different question , not part of answer explicit question


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -