No need to transform into array, just call the method charAt()
by passing the position of the letter as 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 on ideone.
Obs.: it is always good to check if the last Dice is smaller than the string size by checking seuIndice < palavra.length
because if the Dice passed to this method is larger than the string size, an exception will be made IndexOutOfBoundsException
.
Remembering that a word’s input starts from 0 to the size of the String -1.
But if even with all this ease provided by the language you want to insist on creating array, it is also possible to convert a String into an array of char
, with the method toCharArray()
:
char[] words = "java".toCharArray();
System.out.println("\n"+words[3]);
See also working on IDEONE.
Could you properly format your code? Just select it and type
ctrl + k
– Jefferson Quesado
Okay, I just wanted to make this vector receive a string and I could separate each character of it into a vector index, I don’t know if it was clear
– Dener Souza