开发者

Converting ArrayList<T> to CharSequence[]

I want to convert my ArrayList containing elements with the toString method shadowed in "T":

public String toString(){
    return name + "  " + realname;
}

to a CharSequence array containing all the "T"s toString. Checked some stuff out but nothing works for me since CharSequence[] can't be concatenated (correct me if i'm wrong).

Saw a solution for the ArrayList at -> ArrayList<String> to CharSequence[] which didn't work out for me

I'm doing this because I've searched for devices ("T") and 开发者_开发问答added them to a Arraylist, the user then has to make a choice which one to accept by clicking on a mutliple choice dialogwindow as shown under DIALOG_TEXT_ENTRY in this link

Please help me out cause it's driving me mad


So through the responses via the comments you guys suggested a solution with subsequence. However this is a similar solution I guess and it's semi-implemented in my code already so I'm gonna go with this one with a few modifications ofcourse.

Feel free to still give feedback if it's a bad way to implement or if there actually exists other ways of doing it!

::EDIT::

The solution was the following: I tried ot the code given by the link and take note that my ArrayList.toString() returns a String object with the following look for each element in the List

"[foo, bar, super, duper]"

Taken to account that the toString() is overriden in the my object class. The following is done

    private String[] stringToArray(String str){
    str = str.substring(1, str.length()-1);
    String[] str2array = str.split(", ");

    return str2array;
}

And voila I have the String[] array and can now represent them as choices in my single choice list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜