I'm writing a method where it take an array, checks to see if the negative value of an element in the array is present, if it is, then it returns both the value(positive and negative).
I'm coming from python, where you can use if i is in n
, but I don't see any similar methods with Jave. I've read around and saw there are more than one method, but they require over 6+ lines of code.. I was wondering if there was a shorter way for something this simple?
My planned algorithm is to take i in a(the array),
multiply i*-1 = x
.
if x is in the array, then it adds it to an Arraylist
that returns at the end of the for loop