2

I need to make sure that a certain long value isn't in an array. But for some reason, this isn't working...

!d.toString().contains(sq.toString());

I am sure I am getting something really backwards... but I can't figure out what!

Isaac Lewis
  • 1,189
  • 2
  • 14
  • 26
  • Assuming that `d` is actually the array, then `.toString()` is not going to do what you're thinking -- it's not going to print out the elements of the array, and thus testing `contains` on that string is useless. – Kirk Woll Feb 15 '11 at 22:05
  • I would suggest checking for equality instead contains because: `"12345".contains("123")` returns `true` which is probably not what you want (assuming `d` and `sq` are string representations of the longs). – armandino Feb 15 '11 at 22:07

2 Answers2

7

Try

!Arrays.asList(d).contains(sq);
Bala R
  • 107,317
  • 23
  • 199
  • 210
0

Look at the static methods in java.util.Arrays. Your array will need to be sorted for the binarySearch() to work.

Chesrae
  • 345
  • 1
  • 3
  • 4