For example, the following code:
char[] help = new char[20];
help[0] = 'a';
help[1] = 'b';
String me = new String(help);
gives me an string of length 20, while I want a
string of length 2. Do I have to use the string
buffer class and manually copy each element of
the array or is there an easier way?
--
-Nathan (remove the junk for my email)
In article <7qnb77$h9d$1...@agate-ether.berkeley.edu>, nat...@liriel.HIP.berkeley.edu (nathan) writes:
> How would I create a string from char array so that
> the string is shorter than the array?
To start with, none of the problems in HW1 require such a conversion.
You can use the type String for everything without ever using char
arrays. Indeed, this is how such tasks are almost invariably done in
Java.
However, if you really must perform this conversion, I suggest that
you look at the constructors for String that are described in the
on-line Java library documentation (under String).
PNH