- #1
magnifik
- 360
- 0
For the following segment of code, I am getting a null pointer exception when trying to access any value in a list (doubly-linked with dummy nodes) AFTER a null value. For example, if I have the following list of integers:
0, 1, 2, 3, null, 4, 5
and I run the function list.contains(0) or list.contains(1)...list.contains(null), the program works as it should. When I try to call list.contains(4) or list.contains(5), I receive a null pointer exception. I know the order in which I use == and .equals() matters, but should I separate it into multiple if statements? I tried to do so, and I was not receiving any different results.
for (Node cursor = _head._next; cursor != _tail; cursor = cursor._next){
if ((o == null & cursor._data == null) || cursor._data.equals(o)) // o is the Object data
return true;
0, 1, 2, 3, null, 4, 5
and I run the function list.contains(0) or list.contains(1)...list.contains(null), the program works as it should. When I try to call list.contains(4) or list.contains(5), I receive a null pointer exception. I know the order in which I use == and .equals() matters, but should I separate it into multiple if statements? I tried to do so, and I was not receiving any different results.
for (Node cursor = _head._next; cursor != _tail; cursor = cursor._next){
if ((o == null & cursor._data == null) || cursor._data.equals(o)) // o is the Object data
return true;