String Methods

Cards (11)

  • "String".equals("String") - returns true if the two strings are equal (Strings)
  • myStr1.equals(myStr2) - returns true if the two strings are equal.
    (Variables)
  • myStr1.compareTo(myStr2) or "String".compareTo("String")
    Returns 0 if the first string is equal to the other string.
    <0 is returned if the first string is less than the other (less characters).
    >0 if the first string is greater than the other string (more characters).
  • Initialize and Declare: String varname = "anyword"
  • varname.length() - returns number of characters in a string.
  • varname.substring(int index) - returns substring from that point up until end of string.
  • varname.indexOf(letter) - returns the index of the first occurrence of the string letter. -1 if not found.
  • varname.substring(startindex, endindex) - returns substring from starting point up until the end, excluding the end index.
  • String varname = new String("anyword") - Creates string object
  • Attempting to access indices outside of a substring range will cause an IndexOutOfBoundsException to be thrown.
  • varname.indexOf(letter, startindex) - returns the index of the first occurrence of the string letter after startindex. -1 if not found.