Lecture #6

An Introduction to Programming: Coding Decision Trees

Strings and String Manipulation

  • The String Class
    Declaration:
    String message;
    String Constant
    "Good Morning World!"
    String Assignment
    message = "It's Friday";

  • String Has Many Methods for Manipulation
    • Most important ones are: length(), indexOf(), substring()

  • int length()

  • int indexOf(String st)

  • String substring(int start, int end)

  • Getting String Data from the User
    • The TextField class has getText() method.
    • Can use:
      message = mg.getText();
      where mg is a TextField and message is a String.

  • Exchanging the Contents of Two Variables

  • Example Doing Some String Manipulation
    StringPlay.java, StringPlay.html

  • Add More Functions
    • Last name first format
    • All Capitals ( String toUpperCase())