假如忽略元素的次序性,建议用Hashtable

解决方案 »

  1.   

    见remove方法,从指定的数组中移除指定下标的元素。
    不要用Vector,用java.util.Arrays和java.util.List.
    ================================================
    public class ArrayRemover {
        private ArrayRemover() {}    public static Object[] remove(Object[] src, int index) {
            if(src==null||index<0||index>src.length) {throw new IllegalArgumentException();}
            List list = new ArrayList(Arrays.asList(src));
            list.remove(index);
            return list.toArray();
        }
    }
    单元测试代码:
        public class TestArrayRemover extends TestCase {
        public TestArrayRemover(String name) {super(name);}    public void testRemove() {
            String[] src = {"1","2","3"};
            Object[] dst = ArrayRemover.remove(src, 0);
            assertEquals(2, dst.length);
            assertEquals("2", dst[0]);
            assertEquals("3", dst[1]);
        }
    }