IntScription()
← Back to Notes Home
  • Strings are used to sort text
  • Contains collection of characters surrounded by " "
public class Example{
  public static void main(String[] args){
    String greeting = "Hello";
  }
}

String Length

  • A String is actually an object
  • Can be found using length()
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
System.out.println("The length of the txt string is: " + txt.length());

Some Other Examples

String txt = "Hello World";
System.out.println(txt.toUpperCase());   // Outputs "HELLO WORLD"
System.out.println(txt.toLowerCase());   // Outputs "hello world"
String txt = "Please locate where 'locate' occurs!";
System.out.println(txt.indexOf("locate")); // Outputs 7

[!Note] Java counts positions from zero.
0 is the first position in a string, 1 is the second, 2 is the third …