Получите первые 5 символов String Java
firstFourChars = input.substring(0, 4);
Xenophobic Xenomorph
firstFourChars = input.substring(0, 4);
var string = "freeCodecamp";
string.charAt(0); // Returns "f"
// Array of names
String name [] = {"Clark", "Bruce", "Diana", "Barry"};
// for each loop (to iterate everything inside the array)
for (String names: name) {
System.out.println(names.charAt(0));
}
/* Prints
C
B
D
B
*/
String words = "Hi There"; //creating a string var named 'words'
char index = words.charAt(0); /* setting a variable 'index' to letter
'0' of variable 'words'. In this case, index = 'H'.*/
System.out.println(index); //print var 'index' which will print "H"
String str = "Grepper";
char ch = str.charAt(0);
//ch is assigned the value of G