Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: comparison of two string Date: Mon, 24 Feb 2014 07:59:41 -0500 Organization: A noiseless patient Spider Lines: 30 Message-ID: References: <43f5b47b-d5ef-46e4-b6cd-af228c1742df@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 24 Feb 2014 12:59:39 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="858a9d65d95f4ea4d355bd116aa2cdbf"; logging-data="27478"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182YJY4gDXjtuL1omuWGwQY" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: Cancel-Lock: sha1:YL89PrVBGToKwIIC/xbRKoEjhXg= Xref: csiph.com comp.lang.java.programmer:27583 On 2/24/2014 5:46 AM, Andreas Leitgeb wrote: > Navneet Mathpal 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