2011-12-03 7 views
6

equals()と同様の方法が「等しくない」と表現されていますか?2つの値が互いに等しくないことをどのように表現できますか?

私が達成しようとしているものの例は以下の通りです:

if (secondaryPassword.equals(initialPassword)) 
{ 
    JOptionPane.showMessageDialog(null, "You've successfully completed the program."); 
} else { 
    secondaryPassword = JOptionPane.showInputDialog(null, "Your passwords do not match. Please enter you password again."); 
} 

私はif (a != c)を使用するために私を必要としない何かを見つけようとしています。

+0

得ることはありません'!string.equals(..)'(これはメソッド 'notEquals')のようなものを使うと、ORを使わないようにするのに役立ちます。 – talnicolas

+0

私は '(a!= b)'と打つことを意味しました。私の悪い。それを指摘してくれてありがとう。 – cdo

答えて

3
if (!secondaryPassword.equals(initialPassword)) 
20

の前で「ない」オペレータ!と標準.equalsで表現することができる「に等しいありません」。

if (a.equals(b)) // a equals b 
if (!a.equals(b)) // a not equal to b 
0

クラスがComparableを実装する場合は、

int compRes = a.compareTo(b); 
if(compRes < 0 || compRes > 0) 
    System.out.println("not equal"); 
else 
    System.out.println("equal); 

!を使用していない行うことができ、特に有用ではないものの、または私が読める....

関連する問題