In Java, I'm trying to know whether an Integer is in an ArrayList<Integer>. I tried using this general solution, which warns that it doesn't work with arrays of primitives. That shouldn't be a problem, since Integers aren't primitives (ints are).
ArrayList<Integer> ary = new ArrayList<Integer>(); ary.add(2); System.out.println(String.format("%s", Arrays.asList(ary).contains(2))); Returns false. Any reason why? Any help is appreciated, although the less verbose the better.
Arrays.asList(ary)?arywas declared as anArrayList<Integer>?ArrayList<T>inherited fromList<T>and thus already had acontains()method... This was kind of a trivial question, so I'll leave it up to the community to decide whether to keep it or not.