title: test cases for reversing a string
body: <p>I am trying to practice for a QA interview and I want to handle as many test cases as I can think of. I believe my method works for every case except when the input is <code>null</code> I am not sure how to handle that exception. The compiler will give me an error first before the code even runs. So I am not sure how to deal with that exception. I read around and <code>catch</code>ing the <code>NullPointerException</code> is not recommended. How would I deal with handling a <code>null</code> input. Also if anyone else can think of other test cases, I would be happy to test and have a look at it!</p>
  
  <p>Here are my test cases:</p>
  
  <pre><code>""
  "abcdef"
  "abbbba"
  null
  </code></pre>
  
  <p>not quite sure how to handle</p>
  
  <p>escape characters</p>
  
  <pre><code>"\n"  --&gt; "n\"
  "\t"  --&gt; "t\"
  </code></pre>
  
  <p>special characters such as </p>
  
  <pre><code>áe  --&gt;  eá 
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>public static String reverseStr(String str) {
      int len = str.length();
      if (len &lt;= 0) {
          return "Empty String";
      }
      char[] strArr = new char[len];
      int count = 0;
      for (int i = len - 1; i &gt;= 0; i--) {
          strArr[count] = str.charAt(i);
          count++;
      }
      return new String(strArr);
  }
  </code></pre>
  
  <p>After further suggestions here is the updated code:</p>
  
  <pre><code>public static String reverseStr(String str) {
      if ( str == null ) {
            return null;
      }
      int len = str.length();
      if (len &lt;= 0) {
          return "";
      }
      char[] strArr = new char[len];
      int count = 0;
      for (int i = len - 1; i &gt;= 0; i--) {
          strArr[count] = str.charAt(i);
          count++;
      }
      return new String(strArr);
  }
  </code></pre>