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"?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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;"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?
Last edited by helloworld922; April 3rd, 2010 at 09:50 PM.
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.
// 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.
for (int i = 0; i < myVector.size(); i++) { char theCharacter = myVector.get(i); }
nasi (April 3rd, 2010)
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.