Docsity

Java Programming: Objects, Classes, Strings and Comparison, Study notes of Computer Science

Partial preview of the text

Download Java Programming: Objects, Classes, Strings and Comparison and more Study notes Computer Science in PDF only on Docsity!

SubString question

s.substring(i, j) returns: ???

  • (^) first j characters of s starting at index i
  • (^) first j-1 characters of s starting at index i
  • (^) s starting at index i and ending at j
  • (^) s starting at index i and ending at j-

object and classes and Strings

  • (^) What's the difference between =, ==, and equals?
  • (^) How can I check whether a string s is the empty string?
  • (^) Is there a difference between the empty string and null?
  • (^) if the following legal? s.trim().toLowerCase().equals("saturday")

int compareTo(String anotherString)

let k be the smallest such index; then the string whose character at position k has the smaller value, as determined by using the < operator, lexicographically precedes the other string.

  • (^) this.charAt(k)-anotherString.charAt(k) if there no such index
  • (^) this.length()-anotherString.length() returns: integer