You code does not seem too clean / clear, neither your question ! Could you reformulate ? Also, in the code, and w/o knowing much about the thing you want to do the 4 th line seems really strange !
Also I wonder why you did not created your own Vector class. It seems that you could take a lot more out of it when implementing your own toString() method, like what follows !
publicclass MyCustomVector
extends java.util.Vector
{
...
public String toString()
{
synchronize(this)
{
Object[] o = this.toArray();
// Check if this is fast enough or may be you could try to access the
// protected Object[] elementData of the java.util.Vector
} // End of synchronization
StringBuffer buf = new StringBuffer();
// This is not excatly what you want but
// removing the last comma should not be an issue
//
for (int i = 0; i < o.length; i++)
buf.append(o[i]).append(',');
// Please not that the forum has a problem.
// It dislays comparison (greater/smaller) signs around the "i"
// They are in fact square brackets, instead !!!
return buf.toString();
}
I will start with (trying to) clarifying the code.
String line; // I need a string to read a line from the file.
while ( (line = bufferedReader.readLine()) != null) { // I need to convert the string to a Vector to // prevent casting problems in getValueAt() method. Vector aLine = new Vector();
// Tokenizer to convert the string to vector aLine.add(stringToVector(line));
// I need to add the vector to a Vector data.addAll(aLine); }
I am trying to have a JTable which can read data from file, add rows, and save the entire table to a file.
However, somewhere in the converting of string to vector and adding this to a vector, it adds a space between every column which I do not want.
Creating my own vector class was something I did not think off. I am pretty new to Java and I am not used to override methods from existing classes, partly cause I am not sure I can do that. But I will give it a go.
Hope this clarifies somewhat.
Thanks for your answer and suggestion.
Grtx, Barry (I forgot to mention my name the first time. Willy was just some sample data for my JTable.)
publicstatic Vector stringToVector(String string)
{
// can't you give a char ',' instead of a String ","
StringTokenizer tokenizer = new StringTokenizer(string, ",", false);
Vector row = new Vector();
while(tokenizer.hasMoreTokens())
{
String valueOfToken = tokenizer.nextToken();
// trimming the String before adding it ?
row.addElement(valueOfToken.trim());
}
return row;
}