2014-11-12 19 views
6

Tôi đang cố gắng lấy tệp kết xuất mở rộng arrf từ một mảng đa chiều trong Java. Và tôi đã nhập thư viện weka, tuy nhiên tôi gặp lỗi; The type FastVector<E> is deprecated.Loại FastVector <E> không được dùng nữa

Tôi có thể sử dụng gì thay vì FastVector và cách tôi có thể viết lại mã bên dưới?

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(); 

Trả lời

13

Hiện tại, chúng tôi sử dụng các ArrayLists được nhập nhiều nhất. Bạn có thể sử dụng ArrayList<Attribute> cho việc này:

ArrayList<Attribute> atts = new ArrayList<Attribute>(); 
    for (int att = 0; att < numAtts; att++) { 
     atts.add(new Attribute("Attribute" + att, att)); 
    } 
+2

Vâng, tôi thấy điều đó, nhưng làm cách nào tôi có thể sử dụng ArrayList ở mã trên? – EngineerEngin

+0

Tôi đã chỉnh sửa phản hồi của mình bằng đoạn mã. Nó sẽ đơn giản như thay đổi loại biến atts của bạn. – Chris

+0

Cảm ơn, nó hoạt động. Lỗi FastVector đã biến mất. – EngineerEngin

Các vấn đề liên quan