Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

compareTo

 
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the base in order to compare strings?

The compareTo method is used when we need to determine the order of Strings lexicographically


http://www.javabeginner.com/learn-java/java-string-comparison

What does it mean?

For example: "this is my cat"

"green road"

What is the base in order to compare these sentences?








 
Greenhorn
Posts: 17
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

what is the base in order to compare strings?


What do you mean with base?
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How two strings compare?
How a string be greater?
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you read the documentation? Because there it is mentioned in the second sentence.
 
Frederick Winsnes
Greenhorn
Posts: 17
Android Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abalfazl hossein wrote:How two strings compare?
How a string be greater?



 
Ranch Hand
Posts: 87
Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If not satisfied by java doc , you can have a look at the below link to understand what is lexicographical order !!
http://en.wikipedia.org/wiki/Lexicographical_order
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The output of the statements is
1
-31
32
0
The fi rst int displayed from line 8 is positive because the string “ hello ” is greater than
“ goodbye “ . The actual value of the positive number is normally irrelevant, and for String
objects it represents the difference between the fi rst unequal characters between the two
strings. Line 9 compares “ Hello ” to “ goodbye ” and outputs - 31 because H is uppercase and
appears before all lowercase letters. Therefore, “ Hello ” is less than “ goodbye “ . Similarly,
“ hello ” is greater than “ Hello ” on line 10, which outputs 32 . Line 11 outputs 0 because
the two strings are equal



From:

Sun Certified Programmer
for Java® Platform, SE6
 
Won't you be my neighbor? - Fred Rogers. tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic