Article View: borland.public.jbuilder.java.api
Article #1101Re: < or >
From: Reiz
Date: Thu, 20 Jun 2002 20:02
Date: Thu, 20 Jun 2002 20:02
65 lines
2877 bytes
2877 bytes
yes I means to compare strings lexicographiclly.
I have a solution:
if (string1.compareTo(string2) == -1) // string1 < string2
{
.... code .....
}
if (string1.compareTo(string2) == 1) // string1 > string2
{
.... code .....
}
if (string1.compareTo(string2) == 0) // string1 == string2
{
.... code .....
}
Rob
"Alexander Petry" <alex_petry-nospam@web.de> schrieb im Newsbeitrag
news:87660d912w.fsf@nbook.wohnheim.uni-kl.de...
> On Thu, 20 Jun 2002, coff@online.no spake thusly:
>
> > You can not compare two strings using less-than or greater-than.
> > What are you trying to accomplish? compare the size or?
>
> I think, that he means how to compare strings lexicographically.
>
> >
> > On Thu, 20 Jun 2002 21:30:23 +0200, "Reiz" <RReiz@gmx.de> wrote:
> >
> >>How can I do it in Java
> >>
> >>If (String1 < String2) then
> >> ...
> >> code ....
> >> ....
> >>end if
> >>
>
> Have a look at the java api of the String class. It says this:
>
> ,----[ compareTo(String s) method ]
> | compareTo
> |
> | public int compareTo(String anotherString)
> |
> | Compares two strings lexicographically. The comparison is based on
> | the Unicode value of each character in the strings. The character
> | sequence represented by this String object is compared
> | lexicographically to the character sequence represented by the
> | argument string. The result is a negative integer if this String
> | object lexicographically precedes the argument string. The result is a
> | positive integer if this String object lexicographically follows the
> | argument string. The result is zero if the strings are equal;
> | compareTo returns 0 exactly when the equals(Object) method would
> | return true.
> | ...
> |
> `----
>
>
> Alex
Technical Details
Message-ID:
<aetcb6$9rcg1$1@ID-97157.news.dfncis.de>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!212.65.18.129!not-for-mailReferences:
<aetafp$9tjac$1@ID-97157.news.dfncis.de> <3d122f57.20062197@news.online.no> <87660d912w.fsf@nbook.wohnheim.uni-kl.de>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113ae9,59a0cb87210dc727 X-Google-Attributes: gid113ae9,public X-Google-Thread: 1089d0,59a0cb87210dc727 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-06-20 13:01:44 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!212.65.18.129!not-for-mail From: "Reiz" <RReiz@gmx.de> Newsgroups: borland.public.jbuilder.java.api,comp.lang.java.help Subject: Re: < or > Date: Thu, 20 Jun 2002 22:02:04 +0200 Lines: 67 Message-ID: <aetcb6$9rcg1$1@ID-97157.news.dfncis.de> References: <aetafp$9tjac$1@ID-97157.news.dfncis.de> <3d122f57.20062197@news.online.no> <87660d912w.fsf@nbook.wohnheim.uni-kl.de> NNTP-Posting-Host: 212.65.18.129 X-Trace: fu-berlin.de 1024603302 10334721 212.65.18.129 (16 [97157]) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000