Re: noob question about boolean methods
justineee wrote:
public boolean contains()
{
boolean x=false;
if (list.contains("sales")==true
&& list.contains("cost of goods sold")==true)
{
x=true;
return x;
}
return x;
}
My goodness, what an obfuscation! You don't need to compare a
'boolean' value to 'true' or 'false'; you can just use it directly.
public boolean contains()
{
return list.contains( "sales" )
&& list.contains( "cost of goods sold" );
}
With an expression that short, one wonders if wrapping it in a method
hides too much. So the client code could avoid the intermediate call
to 'contains()' altogether and just use the expression, so
if ( contains() )
becomes
if ( list.contains( "sales" )
&& list.contains( "cost of goods sold" ))
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
Please do not quote sigs.
I transfer the words from initlist.txt to the ArrayList using
FileReader.. Will this make any difference? Because when I show the
words they are all correct but not in the boolean method..
<http://sscce.org>
Come on, you've been around long enough to know that, absent an SSCCE,
the error is always in the code you don't show.
--
Lew