This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem using toString()

 
Sadhu Yadav
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 167
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But can someone tell me whats wrong in the line marked //Error.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
output[i]=(myList.get(i)).toString();
 
Sadhu Yadav
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Mate. This solves my prob.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic