title: Java - Most Efficent way to traverse a String
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/196830/what-is-the-easiest-best-most-correct-way-to-iterate-through-the-characters-of-a">What is the easiest/best/most correct way to iterate through the characters of a string in Java?</a>  </p>
  </blockquote>
  
  
  
  <p>What I'm considering is time and efficiency. With those in mind, which method (among the ones below or others not mentioned) is the most efficient way to go through each character of a string?</p>
  
  <pre><code>String str = "Foo Bar";
  for(int i=0;i&lt;str.length();i++)
     System.out.println(str.charAt(i)); // access the character using .charAt()
  
  for(char letter: str.toCharArray)
     System.out.println(letter);       // use for-each loop with the char array.
  </code></pre>
  
  <p>Again, there might be a better way to do this, but I also am curious if there is are major time/resources differences between the two above. </p>