在這樣的試驗:的java:字符串數組的列表,並刪除
@Test
public void test() {
List<String[]> l = new LinkedList<String[]>();
l.add(new String [] {"test", "123"});
l.add(new String [] {"test", "456"});
l.add(new String [] {"test", "789"});
assertEquals(3, l.size());
l.remove(new String [] {"test", "456"});
assertEquals(2, l.size());
}
第二斷言(= 2)如在list.remove
使用的equals/hashcode
是default
爲對象失敗。 有沒有辦法讓列表能夠使用Arrays.equals/Arrays.hashcode
來比較數組?或者唯一的解決方案是將字符串數組包裝在一個對象中並覆蓋equals/hashcode
?
好吧!我會使用GUAVA!番石榴! GUAVAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!謝謝 :) – Randomize