I have a vector of characters for example [e,m,a] but I need to have a String in which all characters are in a same word such as "ema", how should I change [e,m,a] to "ema"?
Printable View
I have a vector of characters for example [e,m,a] but I need to have a String in which all characters are in a same word such as "ema", how should I change [e,m,a] to "ema"?
it generates an error"[Ljava.lang.Object; cannot be cast to [Ljava.lang.String;"Code :int ch; Vector<Character> result = new Vector<Character>(50, 10); String[] Results ; while ((ch=inputStream.read()) > 0) { result.add((char)ch); } Results = new String[result.size()]; Results= (String[])(result.toArray());
what should I do if I need to convert a vector of chars to an string?
Please don't post the same question in two different forums and please use [code] tags.
You can use a StringBuilder object and add characters as you go. There's no need to read in the data if you already have it.
Code :// to append stuff to a StringBuilder // this code appends the character 'h' to the end of the StringBuilder object StringBuilder myStringBuilder = new StringBuilder(); myStringBuilder.append('h');
To get the character at each position on the Vector, use a for-loop across the size of the vector.
Code :for (int i = 0; i < myVector.size(); i++) { char theCharacter = myVector.get(i); }
Thank you very much helloworld992. sorry for that. I don't undrestand what you mean by use [code] tags.
Please see Rule #1 for how to use [code] tags.