Letting str and str2 be of type String, k and m be of type int, and ch be of type char, here are examples of invocations of methods in the java.lang.String class:
method Invocation |
Return Type | Value Returned |
---|---|---|
str.length() | int | length of str |
str.equals(str2) | boolean | true if str and str2 are equal (meaning that their values are identical sequences of characters), false otherwise |
str.indexOf(ch) | int | lowest-numbered position in str at which ch occurs, or -1 if there are no occurrences. |
str.indexOf(ch,k) | int | lowest-numbered position not less than k at which ch occurs in str, or -1 if there are no such occurrences. |
str.lastIndexOf(ch) | int | highest-numbered position in str at which ch occurs, or -1 if there are no occurrences. |
str.lastIndexOf(ch,k) | int | highest-numbered position not greater than k at which ch occurs in str, or -1 if there are no such occurrences. |
str.substring(k,m) | String | substring of str extending from position k through position m-1. |
str.substring(k) | String | suffix of str starting at position k. |
str.charAt(k) | char | character at position k of str. |
str.concat(str2) |
String | string that results from concatenating str and str2. |
str.trim() | String | string identical to str except that any leading or trailing whitespace characters (e.g., spaces, tabs) have been removed |
str.toUpperCase() | String | string identical to str except that any lower case letters have been replaced by their upper case counterparts |
str.toLowerCase() | String | string identical to str except that any upper case letters have been replaced by their lower case counterparts |