5

Android How to Convert List<String[]> to String[].....

4
  • 1
    You can't do that. A List<String[]> is something that contains many String[]s. Unless you're trying to flatten the list and combine all your inner String[] elements into a single String[] array. Commented Apr 9, 2011 at 6:57
  • What a question? You are the winner of "Most impressive question". Give more details with your question to have good answers Commented Apr 9, 2011 at 6:58
  • What do you have, List<String> to convert to String[] or List<String[]> to convert to String[][]? Commented Apr 9, 2011 at 7:01
  • @Dante isn't then two problems? One easy (List<String> to String[]) and one more interesting (String[] to String) Commented Apr 9, 2011 at 7:33

2 Answers 2

10
    static String[] convert(List<String[]> from) {
        ArrayList<String> list = new ArrayList<String>();
        for (String[] strings : from) {
            Collections.addAll(list, strings);
        }
        return list.toArray(new String[list.size()]);
    }

Example use:

    public static void main(String[] args) {
        List<String[]> list = new ArrayList<String[]>();
        list.add(new String[] { "one", "two" });
        list.add(new String[] { "three", "four", "five" });
        list.add(new String[] { "six", "seven" });
        String[] converted = convert(list);
        System.out.print(converted.toString());
    }
Sign up to request clarification or add additional context in comments.

Comments

1

If you are trying to convert a List< String> to a String[ ], you can use List.toArray()

Comments

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.