title: Using ListIterator to get the Next and Previous elements from the Current element of the List
body: <p>I have list of element for that I have to match some specified element and get the previous and next for that element.</p>
  <p>The problem here is when you do <code>iterator.next()</code> or <code>iterator.prev()</code> it returns the same element because the cursor is moved back and forth returning to the same element. So what I did is I use <code>previousIndex()</code> and <code>nextIndex()</code> method to get only index and retrieve element from the list from that index.</p>
  <p>Also make sure to do decrement from previous index as cursor is moved to next element so current element will be returned.</p>
  <pre><code>for (final ListIterator&lt;Xyz&gt; iterator =  nodeList.listIterator();iterator.hasNext();){
              if(iterator.next().equals(midString.get())) {
                  final Xyz prev=nodeList.get(iterator.previousIndex()-1);
                  final Xyz next= nodeList.get(iterator.nextIndex());
                  return some condition true;
              }
          }
  </code></pre>
  <p>Wanted to know is there any better approach to achieve same or any improvements in existing solution.</p>