You can access the letters in a String using method charAt. Check the API.
In Java versions >= 5, you can also use the extended for loop:
String s = ...
for(char ch : s.toCharArray()) {
}
Here is a really bad way to do it:
String word= "this is a test";
String firstLetter = (String[])(new ArrayList(new ArrayList(Arrays.asList(word.split(""))).subList(1,word.split("").length))).toArray(new String[]{})[0];
i think that should work
> Here is a really bad way to do it:
> > String word= "this is a test";
> String firstLetter = (String[])(new ArrayList(new
> ArrayList(Arrays.asList(word.split(""))).subList(1,wor
> d.split("").length))).toArray(new String[]{})[0];
>
> i think that should work
I hate you a little bit now after seeing that. ;P
me too.. i made a small mistake:
String word= "this is a test";
String firstLetter = ((String[])(new ArrayList<String>(new ArrayList<String>(Arrays.asList(word.split(""))).subList(1,word.split("").length))).toArray(new String[]{}))[0];
System.out.println("first letter: "+firstLetter);
works like a charm! gets the first letter every time