Hi All I am a newcomer here,
I am using the following code from an open source library (Matrix Toolkits for Java) which outputs the following matrix
1000 1000 5 3 5 1.000000000000e+00
I am trying to do a String split that will return me 1000,1000,5
I tried using String[] parts = str.trim().split('\\s');
but it seems using the \s as a String Token is wrong, any idea what I should use instead?
thanks a lot!
public String toString() { // Output into coordinate format. Indices start from 1 instead of 0 Formatter out = new Formatter(); out.format('%10d %10d %19d\n', numRows, numColumns, Matrices .cardinality(this)); for (MatrixEntry e : this) if (e.get() != 0) out.format('%10d %10d % .12e\n', e.row() + 1, e.column() + 1, e .get()); return out.toString(); }
You should split on any number of spaces, not just single ones. That is, add ‘+’ to your regexp like this: