equals() vs == in java
class EquDiff
{ public static void main(String args[]) { String a="xyz"; String b=new String("xyz"); String i="xyz"; String j="xyz"; System.out.println("a="+a); System.out.println("b="+b); System.out.println("i="+i); System.out.println("j="+j); if(i==j) System.out.println("i and j equals =="); else System.out.println("i and j not equals !="); if(i.equals(j)) System.out.println("i and j equals equals()"); else System.out.println("i and j not equals()"); if(a==b) System.out.println("a and b equals =="); else System.out.println("a and b not equals !="); if(a.equals(b)) System.out.println("a and b equals equals()"); else System.out.println("a and b not equals()"); } } OutPut: |
0 comments:
Post a Comment