Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cast DefaultListModel into List<Object>?

Tags:

java

I have to put all elements from a DefaultListModel (in a listbox) into a List<Object>. How can I do that in Java?

like image 790
Ante Avatar asked Oct 29 '09 16:10

Ante


People also ask

What is the default list model in portallist?

In Java 1.7, DefaultListModel is genericized. So when you call portalList.getModel (), you're going to get back a DefaultListModel that contains a certain type of object (which is what the <E> is; it's a placeholder for the actual object type.) In the above List<String> example, String is the substitution for E.

How to cast list<object> to customer list?

List<Object> list = getList (); return (List<Customer>) list; you can always cast any object to any type by up-casting it to Object first. in your case: you must be sure that at runtime the list contains nothing but Customer objects.

Is it possible to cast a list of objects to types?

you can always cast any object to any type by up-casting it to Object first. in your case: you must be sure that at runtime the list contains nothing but Customer objects. Critics say that such casting indicates something wrong with your code; you should be able to tweak your type declarations to avoid it.

What is the use of abstractlistmodel in Java?

Fields inherited from class javax.swing. AbstractListModel Inserts the specified element at the specified position in this list. Adds the specified component to the end of this list. Returns the current capacity of this list.


1 Answers

Arrays.asList(model.toArray());
like image 123
jarnbjo Avatar answered Nov 10 '22 01:11

jarnbjo