-1

I have a quick question. I have an array of objects (ODData) and I am trying to cope them into a multidimensional vector so I could do some clustering using Weka. I know it is really simple but for some reason I can't find a proper way in dong so.

new Clustering (routes);
............
............

public class Clustering {

  Vector <Vector<ODData>> myData = new Vector <Vector<ODData>>();

  public Clustering( ODData [] routes )
  {
    //What should I do here?        
  }
}

ODData consists out of three elements if it makes any difference.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
A.J
  • 1,140
  • 5
  • 23
  • 58
  • Are you sure you need `Vector>`? Because `ODData[] routes` can be converted into `Vector`. – Luiggi Mendoza Jul 09 '14 at 15:37
  • If it will keep all the elements of each object then it will work too @LuiggiMendoza – A.J Jul 09 '14 at 15:40
  • You have an array of ODData (`[a, b, c]` for example). You want a vector of vectors of ODData. How many vectors should the outer vector have? What would be the result of this transformation on `[a, b, c]`? – JB Nizet Jul 09 '14 at 15:51
  • possible duplicate of [Java Convert Object\[\] Array to Vector](http://stackoverflow.com/questions/1116636/java-convert-object-array-to-vector) – BackSlash Jul 09 '14 at 15:52
  • 1
    Side note: Use `ArrayList` instead of `Vector` if you can. There usually isn't much reason to use the latter. – awksp Jul 09 '14 at 16:04

1 Answers1

1

Try this:

public void Clustering( ODData[] routes )
{
    Vector<ODData> routesVector = new Vector<ODData>();
    for (ODDatas s : routes) {
        routesVector.add(s);
    }
    myData.add(routesVector);     
}
rob
  • 1,286
  • 11
  • 12