aspose file tools*
The moose likes Beginning Java and the fly likes problem using toString() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem using toString()" Watch "problem using toString()" New topic
Author

problem using toString()

Sadhu Yadav
Greenhorn

Joined: Aug 22, 2005
Posts: 5
I am trying to convert each element of a vector to a string using toString() but its not compiling. Here is the code:

String[] sortString (String []num){

String output[]=new String[num.length];
Vector myList = new Vector();
for(int i=0;i<num.length;i++){
myList.addElement( new Integer(num[i]) );
}
System.out.println("UnSorted list ::" + myList);
Collections.sort(myList);
System.out.println("Sorted list:: " + myList);
for(int i=0;i<num.length;i++){
output[i]=(myList[i]).toString(); //Error
}
return output;
}

Error Says:: array required, but java.util.Vector found
Kudret Serin
Ranch Hand

Joined: Aug 02, 2005
Posts: 167

Hi,
If Error Says:: array required, but java.util.Vector found ,
then you can convert your vector to an array with:
<T> T[] toArray(T[] a)
Returns an array containing all of the elements in this Vector in the correct order; the runtime type of the returned array is that of the specified array.
Cheers.
Sadhu Yadav
Greenhorn

Joined: Aug 22, 2005
Posts: 5
But can someone tell me whats wrong in the line marked //Error.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
output[i]=(myList.get(i)).toString();
Sadhu Yadav
Greenhorn

Joined: Aug 22, 2005
Posts: 5
Thanx Mate. This solves my prob.
 
Don't get me started about those stupid light bulbs.
 
subject: problem using toString()