1

In short, I have an array of words such as {apple, banana, cat} and I'm looking to see if I can convert that into {a, p, p, l, e, b, a, ....} I'm not sure if it's even possible.

My initial stupid attempt:

for(String s: lelWords)
{
    lelChars.add(s.toCharArray());
}
0

2 Answers 2

2
String[] strArray = {"apple", "banana", "cat"};
//combine all words to one string
String combStr = new String();
for(String string: strArray)
    combStr += string;

char[] charArray = combStr.toCharArray();
//checking
System.out.println(charArray);
Sign up to request clarification or add additional context in comments.

Comments

-1

Should be pretty simple

int numChars = 0;

//determine the total number of characters
for (int i = 0; i < strings.length; i++) 
  numChars += strings[i].length();
int idx = 0;

//declare our final array of characters
char[] chars = new char[numChars];

//populate our new array
for (int i = 0; i < strings.length; i++) {
  for (int j = 0; j < strings[i].length; j++) {
    chars[idx] = strings[i].charAt(j);
    idx++;
  }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.