0

if I has a String array:

String[] strArr = {".87654321","2........","3........","4........","5........","6........","7........","8........","9........"}

I want to convert it to char[][]

My way is to add toCharArray() to each String,but it is too trouble:

char[][] charArr = {".87654321".toCharArray(),"2........".toCharArray(),

What is the quick way to convert it to char[][]?

2
  • Please specify quick - quick in sense of fast execution or "quick" in writing short code? Commented Mar 26, 2015 at 9:15
  • writing short code @BinkanSalaryman Commented Mar 26, 2015 at 13:27

1 Answer 1

4

Use a loop:

char[][] convertToTwoDimArray(String[] strArr){
  char[][] ret = new char[strArr.length][];
  for(int i=0; i<strArr.length; i++){
    ret[i] = strArr[i].toCharArray();
  }
  return ret;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Simple, and best answer possible. I was just about to post that one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.