This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
How do I cast a string which is the first Vector element into a char type? i.e I have a Vector which holds strings, and I need to retrieve it inorder to print onto the screen. BUT I need to print the each character individually, which means I have to cast the "string" into type "char" BUT HOW? So far I have this.. System.out.println(sentence.firstElement()); I need a solution ASAP
I believe there is s toCharArray method that you can use. I would personally loop through the string printing out each element of the string. Also check out tghe charAt method.
Bosun
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
I agree with Bosun - I would do something like this: Vector v = new Vector(); v.addElement("One"); v.addElement(""); v.addElement("Two"); v.addElement("Three"); Enumeration e = v.elements(); while(e.hasMoreElements()) { String s = (String) e.nextElement(); for (int i = 0;i < s.length();i++) { char c = s.charAt(i); System.out.println(c); } }
Why do you need to print each character individually? Is it a requirement of your program? If not, you should just print out the entire string at once; your code will be easier to read and maintain. Jason
SCJP, SCWCD
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.