Results 1 to 3 of 3
- 11-16-2010, 01:00 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 11
- Rep Power
- 0
Collections, Collection From one class to another
Hi, im trying to get a collection from one class Department to another Class DeptChooser, so i can put it into an array into a JList and then display it i can get it into a Jlist and display but can't get from Department class into DeptChooser.
here is my bit of code that i thought would work.
[code]
collection.toArray(Department[]);
JList deptList = new JList(dept);
deptList.setSelectionMode(ListSelectionModel.SINGL E_SELECTION);
panel.add(deptList, DeptPanel);
JScrollPane deptListscroll = new JScrollPane(deptList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
panel.add(deptListscroll, DeptPanel);
[\code]
i get a '.class' exspected error
- 11-16-2010, 01:26 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Where is that error thrown?
Full error message and stack trace would be good.
- 11-16-2010, 03:39 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
That first line doesn't work; you have to supply an 'exemplar', i.e. an example array for the method (defined in the Collection interface). So that line should be:
What are you going to do with the array returned by the method? As it is now you simply forget about it. As Tolls already wrote: it would be nice to see a bit more context ...Java Code:collection.toArray(new Department[0]);
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
collection class in java
By katturv in forum New To JavaReplies: 5Last Post: 10-24-2010, 07:09 PM -
Java Collection class & methods
By box2box in forum New To JavaReplies: 2Last Post: 05-26-2010, 01:51 AM -
Collections
By Cbani in forum New To JavaReplies: 3Last Post: 02-16-2010, 02:46 PM -
know the class coming under the collection api in java
By javastuden in forum New To JavaReplies: 1Last Post: 11-24-2009, 07:10 AM -
Collections Help
By Dr Gonzo in forum New To JavaReplies: 0Last Post: 12-07-2008, 09:15 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks