View Full Version : Creating a bash shell in java. HELP!
vik_2010
March 2nd, 2010, 04:35 AM
[]
FreshP
March 2nd, 2010, 04:49 AM
As a general rule, when comparing strings use the method compareTo()
like
if(stringA.compareTo(stringB)==0)........
vik_2010
March 2nd, 2010, 05:02 AM
wow my bad.. thank you. :)
Reiger
March 2nd, 2010, 05:54 AM
In general, if you want to compare objects for equality you use the equals() method:
String str1 = "a";
Object obj2 = new Object();
if(str1.equals(obj2)) {
// this is never reached
}
compareTo() is intended for sorting objects that implement the Comparable interface (hence the integer result).
myrtle1908
March 2nd, 2010, 05:58 AM
As a general rule, when comparing strings use the method compareTo()
like
if(stringA.compareTo(stringB)==0)........
The equals() method is better for this purpose. compareTo() is useful for other reasons beyond the scope of the OPs question.
Also, the line (whilst incorrect)
input == "ls -l" || input == "ls" || input=="ls\n"
would be better served with a regular expression or if you just want to know if 'ls' is present then use indexOf().
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.