java – 不推荐使用FastVector类型

我试图从 Java中的多维数组获取arrf扩展输出文件.我导入了weka库,但是我收到了错误;类型FastVector< E>已弃用.

我可以使用什么代替FastVector以及如何重写下面的代码

import weka.core.FastVector; //Error: The type FastVector<E> is deprecated. 


    int [][] myArray = new int[45194][12541];

    for (int i = 0; i < myArray.length; i++) {
        for (int j = 0; j < myArray[0].length; j++) {
            System.out.print(myArray[i][j]+" "); 
        }
        System.out.println("");
    }

    int numAtts = myArray[0].length;
    FastVector atts = new FastVector(numAtts);
    for (int att = 0; att < numAtts; att++) {
        atts.addElement(new Attribute("Attribute" + att,att));
    }

    int numInstances = myArray.length;
    Instances dataset = new Instances("Dataset",atts,numInstances);
    for (int inst = 0; inst < numInstances; inst++) {
        dataset.add(new Instance(1.0,myArray[inst]));   //Error: Cannot instantiate the type Instance
    }

    BufferedWriter writer = new BufferedWriter(new FileWriter("test.arff"));
    writer.write(dataset.toString());
    writer.flush();
    writer.close();

解决方法

Weka现在大多数地方使用类型化ArrayLists.您可以使用ArrayList< Attribute>为了这:
ArrayList<Attribute> atts = new ArrayList<Attribute>();
    for (int att = 0; att < numAtts; att++) {
        atts.add(new Attribute("Attribute" + att,att));
    }

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...