We are given an array of Strings and what we require is a char[], i.e, array of all characters in all the Strings For example:
Input: [i, love, you]
output: [i, l, o, v, e, y, o, u]
First I made an array of arrays.
Then I have found the length of the required char[] array.
I have tried the following so far:
char[][] a1 = new char[str.length][];
for(int i =0;i<str.length;i++){
a1[i]=str[i].toCharArray();
}
int total=0;
for(int i =0;i<str.length;i++){
total = total + a1[i].length;
}
char[] allchar = new char[total];
for(int i=0;i<str.length;i++){
//NOW HERE I WANT TO MERGE ALL THE char[] ARRAYS TOGETHER.
//HOW SHOULD I DO THIS?
}
string.toCharArray();
Now stop thinking and code. – sᴜʀᴇsʜ ᴀᴛᴛᴀ Oct 25 '13 at 16:05String
documentation would be a good place to start. – GriffeyDog Oct 25 '13 at 16:07How can I ...
is a bad format for StackOverflow questions. StackOverflow questions should typically be in the following format:This is what I want to accomplish. This is what I've tried. Here is the code that I've actually compiled (or attempted to compile). I'm having this result. I'm expecting this result. What have I done wrong?
If you want someone else to write the code to turn an array ofString
s into an array ofchar
, then you should hire a programmer. – nhgrif Oct 25 '13 at 16:12