title: Java list : get next or previous element from an identifier
body: <p>I want to <strong>navigate into a list by identifier</strong>.</p>
  
  <p>1- I manage/create a list.</p>
  
  <p>2- I create function to get next item of a identifier element from my list</p>
  
  <p>Can you help me to fix this code?</p>
  
  <p>Prepare the list</p>
  
  <pre><code>List&lt;String&gt; myList = new ArrayList&lt;String&gt;();
  myList.add("1");
  myList.add("2");
  myList.add("3");
  myList.add("4");
  myList.add("5");
  
  
  public String function getNext(String uid) {
  
      if (myList.indexOf(uid).hasNext()) {
          return myList.indexOf(uid).nextElement();
      }
      return "";
  }
  
  public String function getPrevious(String uid) {
      return myList.indexOf(uid).hasPrevious() ? myList.indexOf(uid).previousElement() : "";
  }
  </code></pre>