Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why we dont have JComboBox(ArrayList items)

 
Vikas Kumar Sahu
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have seen JCombobox API and found

JComboBox(Vector items) constructor.
But why we dont have JComboBox(ArrayList items) constructor having array list as argument.

R
Vikas Sahu


 
Vijay Vaddem
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its ok Vikas..............

But it does take a string array .... right?


To convert a arraylist to string [], do this....



Probably its just bcos we need to do some work!!

Cheers,
Vijay
 
Vikas Kumar Sahu
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Vijay.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or we can use this constructor
JComboBox(Object[] items) which creates a JComboBox that contains the elements in the specified array.

You might use like this...
JComboBox(urArrayList.toArray())

You will get the same objects inside your JComboBox... To minimize the redundancy, Sun might not include JComboBox(ArrayList items) which can be simulated by the method mentioned above...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic