how to bind ArrayList to JList

user765970 picture user765970 · Jun 21, 2011 · Viewed 34.8k times · Source

i have a JList and an ArrayList.How to bind the datas in arraylist to the jlist.Are the any alternative methods?

    ArrayList arl = new ArrayList();
    arl.add("1asdsd");
    arl.add("2asdsd");
    arl.add("3asdsd");  
    Object obj = arl.clone();
    JList list = new JList(obj);

how to bind the above code.Now the code give an error.

Answer

Oleg Pavliv picture Oleg Pavliv · Jun 21, 2011

You don't need to clone the ArrayList. Just call toArray()

JList list = new JList(arl.toArray());