Java: BufferedReader lines compared to String issues -


i have program reading text file has list of items, creates arraylist consisting of items reads, compares few chosen words. example, text file contains (without numbering):

  1. book
  2. desk
  3. food
  4. phone
  5. suit

and reads each 1 , adds arraylist. when tried comparing string s = "book" each element in arraylist, find s not equal anything. have in method:

for (int = 0; < list.size(); i++) { if (s.equals(list.get(i))     return true; } 

s.contains() doesn't work either. when print arraylist, there's additional whitespace @ end of each string element. how can comparison work when s = "book"? why there additional whitespace?

use trim() remove leading , trailing whitespace.

if (s.equals(list.get(i).trim())     return true; } 

instead of

if (s.equals(list.get(i))   return true; } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -