METHODS - String
4 flashcards · Other · by Steven Bui
s.length()
O(1) The length is a field. RETURN: int - length of the string
s.charAt(index)
O(1) The array jumps to the index, rather than scanning each index up to that point. RETURN: char - character at the index
s.contains(substring)
O(n * m) The array checks the length of the substring (n) in the length of the string (m) RETURN: boolean - if string contains substring
s.compareTo(string)
O(min(m, n)) The array compares each character in the lengths of s (n) and the other string (m) RETURN: int - position of s relative to string ---------------------------------------------------------------------------------- String s1 = "hello"; String s2 = "world"; System.out.println(s1.compareTo(s2)); -1