Nebula
03-18-2003, 06:07 PM
</span><table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private String arr2str(char[] chars, int charsRead)
{
Â* Â* Â* Â*String buffer = "";
Â* Â* Â* Â*for (int i = 0; i < charsRead; i++)
Â* Â* Â* Â*{
Â* Â* Â* Â* Â* Â* Â* Â*System.out.println("Loading "+i+"...");
Â* Â* Â* Â* Â* Â* Â* Â*buffer += chars[i];
Â* Â* Â* Â*}
Â* Â* Â* Â*return buffer;
}[/QUOTE]<span id='postcolor'>
I'm trying to convert a character array into a String in Java. Â*The FileReader reads the file into an array of characters. Â*Using the method above to convert the array into a string is painfully slow.
Is there a built-in way for just turning a charater array into a string? Â*using .toString() on the array produces something like: "[C@e51b2c". Â*I hope this isn't *too* easy of a question.
BTW...only reason I'm not going to some source code website and looking this up is because this is part of my Adv. Java program, and I'm only supposed to use JavaDocs or TheJavaTutorial (and if you use that reason for not telling me, I'll just submit a program that takes forever to load big files http://campcaen.engin.umich.edu/iB_html/non-cgi/emoticons/biggrin.gif). Â*The code I *did* submit is so obvious...it's nothing special. Â*If a councelor doesn't like that I posted it, by all means, censor it out. And odds are, if they understand it, they'd have already coded it, or know how to, and if they don't understand it, they won't use it.
{
Â* Â* Â* Â*String buffer = "";
Â* Â* Â* Â*for (int i = 0; i < charsRead; i++)
Â* Â* Â* Â*{
Â* Â* Â* Â* Â* Â* Â* Â*System.out.println("Loading "+i+"...");
Â* Â* Â* Â* Â* Â* Â* Â*buffer += chars[i];
Â* Â* Â* Â*}
Â* Â* Â* Â*return buffer;
}[/QUOTE]<span id='postcolor'>
I'm trying to convert a character array into a String in Java. Â*The FileReader reads the file into an array of characters. Â*Using the method above to convert the array into a string is painfully slow.
Is there a built-in way for just turning a charater array into a string? Â*using .toString() on the array produces something like: "[C@e51b2c". Â*I hope this isn't *too* easy of a question.
BTW...only reason I'm not going to some source code website and looking this up is because this is part of my Adv. Java program, and I'm only supposed to use JavaDocs or TheJavaTutorial (and if you use that reason for not telling me, I'll just submit a program that takes forever to load big files http://campcaen.engin.umich.edu/iB_html/non-cgi/emoticons/biggrin.gif). Â*The code I *did* submit is so obvious...it's nothing special. Â*If a councelor doesn't like that I posted it, by all means, censor it out. And odds are, if they understand it, they'd have already coded it, or know how to, and if they don't understand it, they won't use it.