Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #27579 > unrolled thread
| Started by | Navneet Mathpal <navneetmathpal93@gmail.com> |
|---|---|
| First post | 2014-02-23 23:13 -0800 |
| Last post | 2014-02-24 19:24 -0500 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
comparison of two string Navneet Mathpal <navneetmathpal93@gmail.com> - 2014-02-23 23:13 -0800
Re: comparison of two string Roedy Green <see_website@mindprod.com.invalid> - 2014-02-23 23:16 -0800
Re: comparison of two string Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-02-24 10:46 +0000
Re: comparison of two string Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-02-24 07:59 -0500
Re: comparison of two string Arne Vajhøj <arne@vajhoej.dk> - 2014-02-24 19:24 -0500
| From | Navneet Mathpal <navneetmathpal93@gmail.com> |
|---|---|
| Date | 2014-02-23 23:13 -0800 |
| Subject | comparison of two string |
| Message-ID | <43f5b47b-d5ef-46e4-b6cd-af228c1742df@googlegroups.com> |
why equal is not comparing it although data is same ???
for (int i=0;i<blen;i++)
{
System.out.println("Best :"+best[i]);
String bb=best[i];
for(int j=0;j<flen;j++)
{
String ff=found[j];
System.out.println("Found "+found[j]);
if(bb.equalsIgnoreCase(ff))
{
count=count+1;
System.out.println("hello");
resfound.add(found[j]);
}
}
OUTPUT IS :
Best :17601089
Found 18769218
Found 17601089
Found 7240354
Found 18668662
Found 530777
Found 12538756
Found 15441407
Found 11669171
Found 12062082
Found 12626411
Best : 18668662
Found 18769218
Found 17601089
Found 7240354
Found 18668662
Found 530777
Found 12538756
Found 15441407
Found 11669171
Found 12062082
Found 12626411
Best : 9967149
Found 18769218
Found 17601089
Found 7240354
Found 18668662
Found 530777
Found 12538756
Found 15441407
Found 11669171
Found 12062082
Found 12626411
[toc] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2014-02-23 23:16 -0800 |
| Message-ID | <kbslg91r8m1sd375t46t2oh08uifg9njg8@4ax.com> |
| In reply to | #27579 |
On Sun, 23 Feb 2014 23:13:08 -0800 (PST), Navneet Mathpal <navneetmathpal93@gmail.com> wrote, quoted or indirectly quoted someone who said : >why equal is not comparing it although data is same ??? see http://mindprod.com/jgloss/string.html#COMPARISON -- Roedy Green Canadian Mind Products http://mindprod.com The future has already happened, it just isn’t evenly distributed. ~ William Gibson (born: 1948-03-17 age: 65)
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> |
|---|---|
| Date | 2014-02-24 10:46 +0000 |
| Message-ID | <slrnlgm8od.g8j.avl@login.logic.tuwien.ac.at> |
| In reply to | #27579 |
Navneet Mathpal <navneetmathpal93@gmail.com> wrote: > why equal is not comparing it although data is same ??? According to your output, some of the strings in the found array have an extra whitespace in front. solution: use String.trim()
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2014-02-24 07:59 -0500 |
| Message-ID | <leffnr$qqm$1@dont-email.me> |
| In reply to | #27582 |
On 2/24/2014 5:46 AM, Andreas Leitgeb wrote:
> Navneet Mathpal <navneetmathpal93@gmail.com> wrote:
>> why equal is not comparing it although data is same ???
>
> According to your output, some of the strings in the found array
> have an extra whitespace in front. solution: use String.trim()
A hint for the future: When you're printing string values
for debugging purposes, print something that will make their
endpoints visible even if there's leading or trailing space.
For example, instead of the original
System.out.println("Best :"+best[i]);
System.out.println("Found "+found[j]);
you could try something like
System.out.println("Best: <" + best[i] + ">");
System.out.println("Found <" + found[j] + ">");
so that the output
Best: <17601089>
Found < 17601089>
would reveal the discrepancy more clearly.
--
Eric Sosman
esosman@comcast-dot-net.invalid
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2014-02-24 19:24 -0500 |
| Message-ID | <530be2cd$0$303$14726298@news.sunsite.dk> |
| In reply to | #27583 |
On 2/24/2014 7:59 AM, Eric Sosman wrote:
> On 2/24/2014 5:46 AM, Andreas Leitgeb wrote:
>> Navneet Mathpal <navneetmathpal93@gmail.com> wrote:
>>> why equal is not comparing it although data is same ???
>>
>> According to your output, some of the strings in the found array
>> have an extra whitespace in front. solution: use String.trim()
>
> A hint for the future: When you're printing string values
> for debugging purposes, print something that will make their
> endpoints visible even if there's leading or trailing space.
> For example, instead of the original
>
> System.out.println("Best :"+best[i]);
> System.out.println("Found "+found[j]);
>
> you could try something like
>
> System.out.println("Best: <" + best[i] + ">");
> System.out.println("Found <" + found[j] + ">");
>
> so that the output
>
> Best: <17601089>
> Found < 17601089>
>
> would reveal the discrepancy more clearly.
That is very good advice.
I would use || not <>, but that does not matter.
Arne
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web