If I had a string, say:
String name;
Is there a way I can check each letter with a loop? So if they enter a name can I check what each letter is?
There are several ways to do it - you can do a for loop with an index, or a foreach loop on the char[] array:
for (int i = 0 ; i != s.length() ; i++) {
char c = s.charAt(i);
....
}
for (char c : s.toCharArray()) {
....
}
In addition to checking each letter separately, you can check all letters at once (or any subset that you'd like) with regular expressions.
char[] chars = name.toCharArray();
for (int i =0; i < chars.length; i++)
{
System.out.println(chars[i]);
}
for(char ch: name.toCharArray())This should do
for ( int i=0 ; i < name.length(); i++)
{
name.charAt(i);
}
Also read this http://docs.oracle.com/javase/tutorial/java/data/manipstrings.html
System.out.println(name)