title: Tracking palindromes from a list of strings in Java
body: <p>I have been spending hours trying to work through the logic of finding a palindrome within this context. So we are given an arraylist of strings that are single words and we need to find the biggest palindromes from the list of words. As an example <code>["mr", "owl", "ate", "my", "metal", "worm", "racecar", "mad", "am"]</code> would construct an araylist with the following result <code>["mrowlatemymetalworm", "racecar", "madam"]</code>. So far I have been playing around with the iterations but can't seem to get the correct logic of how to iterate from both ends, especially when it comes to switching inner strings indexes from the other end... Here is what I have so far. </p>
  
  <pre><code>    List&lt;String&gt; list = Arrays.asList("mr", "owl", "ate", "my", "metal", "worm", "racecar", "mad", "am");       
      List&lt;String&gt; palindromeList = new ArrayList&lt;String&gt;(); 
      int i = 0; 
      int j = list.get(i).length(); 
      int l = list.size()-1; 
      int s = list.get(l).length() -1; 
      while (i&lt;j){
  
          while (j&lt;list.get(i).length()){
  
              if (s == 0){
  
                  //need to reinitialize s for previous index of back end of list for possible palindrome  
              }
  
              if (list.get(l).charAt(s) == list.get(i).charAt(j)){
  
                  l--; 
  
              }
  
              else if (list.get(l).charAt(s) != list.get(i).charAt(j)){
  
                  j++; 
                  s--; 
              }
          }
      }
  
      //once outer loop breaks the result should be added to palindromeList
  </code></pre>