VectorUtil { public static String toString(Vector vector) { if (vector instanceof SparseVector) { return toString((SparseVector) vector); } return toString((DenseVector) vector); }  static DenseVector parseDense(String str); static SparseVector parseSparse(String str); static String toString(Vector vector); static String toString(SparseVector sparseVector); static String toString(DenseVector denseVector); static Vector getVector(Object obj); static DenseVector getDenseVector(Object obj); static SparseVector getSparseVector(Object obj);  }
@Test public void testSparseToString() { SparseVector v1 = new SparseVector(8, new int[]{1, 3, 5, 7}, new double[]{2.0, 2.0, 2.0, 2.0}); Assert.assertEquals(VectorUtil.toString(v1), "$8$1:2.0 3:2.0 5:2.0 7:2.0"); }