v.addElement(i);----------方法不支持public void addElement(Object obj)
Adds the specified component to the end of this vector, increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity. 
This method is identical in functionality to the add(Object) method (which is part of the List interface).Parameters:
obj - the component to be added.

解决方案 »

  1.   

    在java 里你可以把二维数组看成一维数组的数组访问
      

  2.   

    我觉得这样实现不了,而且也没什么太大的意义,如果要用vector处理二维数组就直接顺序存储就可以阿,提取就是简单的换算就行了
      

  3.   

    Sorry,对Java尚属初级阶段,难免发生低级错误,举了个不恰当的例子,现在改成:// aaa.java
    import java.util.*;public class aaa {
    public static void main(String[] args) {
    Vector con = new Vector();
    for (int i=0 ; i<5; ++i) {
    Integer obj1 = new Integer(i);
    Integer obj2 = new Integer(2*i);
    Vector v = new Vector();
    v.addElement(obj1);
    v.addElement(obj2);
    con.addElement(v);
    }
    }
    }问题的核心还是一样的:如何才能取出这个Vector模拟的二维数组的任意位置的值,比如如何才能得到第二行第一列的那个Integer对象?如何替换某个位置上的Integer对象呢?谢谢!
      

  4.   

    楼主为什么还用Vector呢?鉴于效率问题,现在都提倡使用ArrayList等新的库,写了一个用ArrayList模拟二维数组的程序,楼主可以参考:import java.util.*;public class Test {
        public static void main(String[] args) {
            ArrayList jellen = new ArrayList();
            
            for(int i=0; i<5; i++) {
                ArrayList array = new ArrayList();
                array.add(new Integer(i));
                array.add(new Integer(i*i));
                jellen.add(array);
            }
            
            System.out.println("array[1][1]: " + ((ArrayList)jellen.get(1)).get(1));
        }
    }不过提取元素的时候比较麻烦,到J2SDK1.5出来就好了,它有自动包箱拆箱机制了。
      

  5.   

    简单阿,v.elementAt(int index)可以取任意位置上的元素,insertElementAt(Object o,int index),setElementAt(Object obj, int index) 可以实现任意存储
      

  6.   

    To JavaVsNet(JavaVsNet):
    是Vector实现不了吗?我把我的目的说一下,看谁能来帮帮我:
    我在用Swing做界面,用到JTable。目的是让JTable显示我从数据库查询到的数据项。
    JTable有个构造函数:
    JTable(Vector rowData,Vector columnNames):建立一个以Vector为输入来源的数据表格,可显示行的名称。
    其中从columnNames中可以提取Column Header(行标题),而从rowData中提取各Column Object(行对象)。由于我设置的行标题是两列的:
    columnNames.addElement("Item");
    columnNames.addElement("Value");因此rowData的格式就必须是一个二维数组,所以才有了类似我上面的模拟二维数组的方法。
    而且程序调试成功,JTable的那个构造函数顺利读取了这两个Vector并显示在窗口上。我现在想读取rowData这个模拟二维数组的Vector的任意位置元素的值,才产生了本问题。(我试过将rowData按一维数组读取,可是JTable的构造函数抛出异常)。谁来帮帮我呢?
      

  7.   

    回复人: JavaVsNet(JavaVsNet) ( ) 信誉:100 
    简单阿,v.elementAt(int index)可以取任意位置上的元素,insertElementAt(Object o,int index),setElementAt(Object obj, int index) 可以实现任意存储那个都是一维的吧?二维的怎么办?
      

  8.   

    我理解错你的意思了。
    你要的功能其实不难,在document中就有说阿
    public JTable(Vector rowData,
                  Vector columnNames)Constructs a JTable to display the values in the Vector of Vectors, rowData, with column names, columnNames. The Vectors contained in rowData should contain the values for that row. In other words, the value of the cell at row 1, column 5 can be obtained with the following code: ((Vector)rowData.elementAt(1)).elementAt(5);Parameters:
    rowData - the data for the new table
    columnNames - names of each column就是说rowData是存放vector的vector了,即每一行用一个vector来存储,然后再将所有vector 放入rowData这个vector里,调用就像例子中说得那样
    ((Vector)rowData.elementAt(1)).elementAt(5);
      

  9.   

    这样能行吗?我昨天好像试过,不过有点不太一样:
    (Vector)rowData.elementAt(1).elementAt(5);
    可能我少了那个括号,晕自己一个!现在再去试试!
      

  10.   

    果然可以,谢谢你了JavaVsNet。