Strings are collections of characters.
String name="Bob";
System.out.println("Hello "+name);
To get the length of a String, you can use the length() method.
String name="Bob"; System.out.println(name.length());
To change your String to upper or lower case, there are the following methods:
String name="Bob"; System.out.println(name.toUpperCase()); System.out.println(name.toLowerCase());
To get a particular character from a String, you can use the charAt() method. Like arrays, Strings start from zero:
String txt="shield";
for(var i=0;i<txt.length;i++){
System.out.print(txt.charAt(i)+".");
}
With the Java JDK installed, from a command line:
class Agent{
public static void main(String[] args){
String name="Bob";
String org="shield";
System.out.print(name+", Agent of ");
// Upper case the string...
org=org.toUpperCase();
// ...then display letter by letter with a dot after.
for(int i=0;i<org.length();i++){
System.out.print(org.charAt(i)+".");
}
}
}
Created (04/05/2025)