Dave's Brain

Browse - Programming Tips - How can I iterate through a String?

Date: 2013nov7
Language: Java


Q.  How can I iterate through a String?

A.	Here is a simple and pretty fast way:

String s = "Hello World"; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); }
Some guy compared all the possible ways for speed: http://stackoverflow.com/questions/8894258/fastest-way-to-iterate-over-all-the-chars-in-a-string

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.