s.equals(sb.toString()) is the only way to check whether the two strings are same or not. s.equals(sb) will return false always because for the s to be meaningfully equals to sb,sb should be either String or any subclass of String(which is not possible).See the equal()(Object overriden) method in String Class.