Utilizor
Contact Us

Java Strings

Text in Java.

Examples

Create String

Basic string creation and length check.

public class Main {
  public static void main(String[] args) {
    String txt = "Hello World";
    System.out.println(txt);
    System.out.println(txt.length());
  }
}

String Methods

Converting to uppercase and lowercase.

public class Main {
  public static void main(String[] args) {
    String txt = "Hello World";
    System.out.println(txt.toUpperCase());
    System.out.println(txt.toLowerCase());
  }
}

Finding a Character

Finding the index of a substring.

public class Main {
  public static void main(String[] args) {
    String txt = "Please locate where 'locate' occurs!";
    System.out.println(txt.indexOf("locate"));
  }
}

Test Your Knowledge

Java Quiz

No quiz available for this topic yet.