You do not have to transform to array, just call the method charAt()
passing the position of the letter, because all String is a CharSequence , that is, a sequence of characters that can be captured using the above method.
String word = "java";
System.out.println("\n"+ word.charAt(3));
See working at ideone .
Note: It is always good to check if the last index is smaller than the string size by checking seuIndice < palavra.length
because if the index passed to this method is greater than the string size, a IndexOutOfBoundsException
.
Remembering that the index of a word starts from 0 to the size of String -1.
But if even with all this language-provided ease you want to insist on creating an array, you can also convert a String to an array of char
, with the toCharArray()
method:
char[] words = "java".toCharArray();
System.out.println("\n"+words[3]);
See also working on IDEONE .