-2

I got a list

List<String> paths = {"r", "e","t","t"};

and I want to add the data of paths into a CharSequence. I have done this code:

CharSequence[] cs = paths.toArray(new CharSequence[paths.size()]);

but I don't know how to add the data in, please help, thanks

Adam Zalcman
  • 26,643
  • 4
  • 71
  • 92
Ricky Zheng
  • 1,279
  • 3
  • 16
  • 27
  • well , thanks guys for the edition, but can you please show me the solution........ – Ricky Zheng Mar 03 '12 at 00:44
  • What is the trouble you are experiencing? You say you don't knwo how to add the data in. In what? What data? What are you getting, versus what are you expecting? – Skip Head Mar 03 '12 at 01:19

1 Answers1

0

The problem is in constructing the list: you can't use array syntax like that. You'll have to add elements one by one --

List<String> paths = new ArrayList<String>();
paths.add("r");
paths.add("e");
...

and then you'll be set.

If you can use third-party libraries like Guava, you could do

ImmutableList<String> paths = ImmutableList.of("r", "e", "t", "t");
Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413
  • 2
    Even if you don't use Guava, you can use `Arrays.asList({...})`. This list will be fixed size. If you want a mutable list, wrap that `List` in the implementation of your choice, e.g., `new ArrayList(Arrays.asList({...}))` – BeeOnRope Mar 03 '12 at 00:58