Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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

like image 257
Jeeva Avatar asked Apr 09 '11 06:04

Jeeva


People also ask

What is a string [] in Java?

In Java, a string is an object that represents a number of character values. Each letter in the string is a separate character value that makes up the Java string object. Characters in Java are represented by the char class. Users can write an array of char values that will mean the same thing as a string.

How do I convert a list to a string in Java?

We use the toString() method of the list to convert the list into a string.


1 Answers

    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());
    }
like image 189
Jim Blackler Avatar answered Oct 06 '22 00:10

Jim Blackler