title: Efficient way for finding Shortest Palindrome from Arraylist of strings
body: <p>I am trying to solve this problem in java. I have an <strong>arraylist of palindromic</strong> strings. I have to find the shortest palindrome string out of the given array list. I have solved the question but was looking at getting feedback on my code and also how I can try to make the code more efficient/better. </p>
  
  <p>Here is the code what I have tried.</p>
  
  <p>In this case, size would be 3, since that is the length of the <strong>smallest palindromic string</strong>.</p>
  
  <pre><code>import java.util.ArrayList;
  class ShortestPalindrome {
      public static int isShortestPalindrome(ArrayList&lt;String&gt; list) {
          int smallest = list.get(0).length();
          boolean ret = false;
          for (String element : list) {
              ret = isPalindrome(element);
              if (ret) {
                  if (element.length() &lt; smallest) 
                      smallest = element.length();                
              }
          }
          return smallest;
      }
  
      private static boolean isPalindrome(String input) {
          String str = "";
          boolean result = false;
  
          if (input.length() == 1 || input.length() == 0)
              return true;
  
          if (input.charAt(0) != input.charAt(input.length() - 1))
              return false;
          StringBuilder sb = new StringBuilder(input.toLowerCase());
          str = sb.reverse().toString();
          if (input.equals(str)) {
              result = true;
          }
          return result;
      }
  
      public static void main(String[] args) {
          ArrayList&lt;String&gt; array = new ArrayList&lt;String&gt;();
          array.add("malayam");
          array.add("aba");
          array.add("abcdeyugugi");
          array.add("nitin");
          int size = isShortestPalindrome(array);
          System.out.println("Shortest length of string in list:" + size);
      }
  }
  </code></pre>