2

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

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.