Jump to content

Search the Community

Showing results for tags 'compareTo'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Calendars

  • Community Calendar

Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 1 result

  1. comparing length of Strings

    Hello, I am trying to comprehend how to compare the length between Strings.i have the following, to compare the length of 10 countries inserted by the user. It also orders them from lowest to highest: public void load() { teclado=new Scanner(System.in); paises=new String[10]; for(int f=0;f<paises.length;f++) { System.out.print("Ingrese el nombre del pais:"); paises[f]=teclado.next(); } } public void ordenar() { for(int k=0;k<9;k++) { for(int f=0;f<9-k;f++) { if (paises[f].compareTo(paises[f+1])>0) { String aux; aux=paises[f]; paises[f]=paises[f+1]; paises[f+1]=aux; } } } } When I use the same method with numbers it works. For instance: public void ordenar() { for(int k=0;k<9;k++){ for(int f=0;f<9-k;f++) { if (vec[f+1]<vec[f]) { int aux; aux=vec[f]; vec[f]=vec[f+1]; vec[f+1]=aux; } } } } So I deduce maybe : if (paises[f].compareTo(paises[f+1])>0) is not correct, because it's the only difference comparing it to the method on numbers.Is there any other way to compare the length between Strings? thank you in advance. p.s I took it from a tutorial which has been working fine till now. I have even checked the "compareTo" on other sites and it seems to be appropriate but I don't know why it's not working here. I would appreciate any help.
×