Results 1 to 4 of 4
  1. #1
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Comparing Strings

    Java Code:
    String s1 = "hello world";
    		String s2 = "hello brother";
    		int result = s1.compareTo(s2);
    		System.out.println(result);
    Output = 21, I know what's the meaning of positive and negative value and value equals to zero but tell me on what basis these values are returned ?
    Last edited by allaudin; 07-01-2013 at 09:47 AM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default Re: Comparing Strings

    'w'-'b' == 21

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Comparing Strings

    Note that the JDK source is freely available and even partly available in the JDK in src.zip, so you can just look it up yourself; generally the JDK code is not rocket science and very easy to follow. If you have your IDE properly setup you should even be able to CTRL+click to the String compareTo() source. Much quicker than asking questions in a forum.

  4. #4
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

Similar Threads

  1. Comparing Strings
    By Adomini in forum New To Java
    Replies: 3
    Last Post: 02-17-2011, 01:20 AM
  2. need in help in comparing Strings
    By jaq in forum New To Java
    Replies: 1
    Last Post: 11-25-2009, 02:06 PM
  3. comparing strings
    By diggitydoggz in forum New To Java
    Replies: 7
    Last Post: 12-23-2008, 05:40 AM
  4. Comparing Strings
    By souFrag in forum Advanced Java
    Replies: 5
    Last Post: 05-21-2008, 10:03 AM
  5. Comparing Strings
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 10:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •