Doubt related two string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hirak1984
    Contributor
    • Jan 2007
    • 316

    Doubt related two string

    Can there be any condition between two strings( say "a" and "b" ) where
    a.equals(b) returns true
    but
    b.equals(a) returns false ?
  • emekadavid
    New Member
    • Mar 2007
    • 46

    #2
    that's a set of strings. nice to do that in java

    Comment

    • prometheuzz
      Recognized Expert New Member
      • Apr 2007
      • 197

      #3
      Originally posted by hirak1984
      Can there be any condition between two strings( say "a" and "b" ) where
      a.equals(b) returns true
      but
      b.equals(a) returns false ?
      No, it is a symetric relation: if a equals b, b equals a.

      Comment

      • emekadavid
        New Member
        • Mar 2007
        • 46

        #4
        thanks for your correction prometheuz. answer is no. String comparison follows character mappings. I saw containment when i threw that answer

        Comment

        • hirak1984
          Contributor
          • Jan 2007
          • 316

          #5
          well thanks for the answer.. to both of you
          Originally posted by emekadavid
          thanks for your correction prometheuz. answer is no. String comparison follows character mappings. I saw containment when i threw that answer

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            I wish that Gosling and his mates had thought a bit more and put in a less()
            method in the Object class too instead of just an equals() method. The default
            implementation could have been:

            [code=java]
            bublic boolean less(Object that) return this.hashCode() < that.hashCode() ; }
            [/code]

            We wouldn't have needed that silly Comparable interface then.

            kind regards,

            Jos

            Comment

            Working...