Java Array Comparison

前端 未结 6 1876
名媛妹妹
名媛妹妹 2021-01-04 19:48

Working within Java, let\'s say I have two objects that, thanks to obj.getClass().isArray(), I know are both arrays. Let\'s further say that I want to compare

6条回答
  •  长发绾君心
    2021-01-04 20:14

    Have you tried this ?

    // Test if both arrays are of the same type
    if (array1.class.getComponentType.equals(array2.class.getComponentTYpe)) {
        // Polymorphism FTW !
        return Arrays.equals(array1, array2);
    }
    

提交回复
热议问题