string equals int 的问题
昨天写程序遇到的一个问题。
public class TestEquals {/*** @param args*/public static void main(String[] args) {String s = "1";Integer i = new Integer(1);System.out.println(s.equals(1));//falseSystem.out.println(s.equals(String.valueOf(1))); //trueSystem.out.println(s.equals(i)); //falseSystem.out.println(s.equals(i.toString())); //true}}
public boolean equals(Object anObject) {if (this == anObject) {return true;}if (anObject instanceof String) {String anotherString = (String)anObject;int n = count;if (n == anotherString.count) {char v1[] = value;char v2[] = anotherString.value;int i = offset;int j = anotherString.offset;while (n-- != 0) {if (v1[i++] != v2[j++])return false;}return true;}}return false;}