Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4873
  • Last Modified:

convert a hashtable to arraylist

Hi ,
Can I convert a HashTable to an ArrayList

thx
0
applekanna
Asked:
applekanna
  • 4
  • 3
1 Solution
 
objectsCommented:
depends if you want the valkues or keys.
to get the keys use:

ArrayList list = new ArrayList(ht.values());

to get the keys:

ArrayList list = new ArrayList(ht.keySet());
0
 
applekannaAuthor Commented:
One question what is the differnce between

using constructor
ArrayList list = new ArrayList(ht.values());

and typecasting
ArrayList list = (ArrayList ) ht.values();

Thx
0
 
objectsCommented:
> using constructor
> ArrayList list = new ArrayList(ht.values());

Creates a new instance of ArrayList

> and typecasting
> ArrayList list = (ArrayList ) ht.values();

Assigns list to the collection returnurned by values().
This will only work if the return instance is an instance of ArrayList (which I'm pretty sure it's not).
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
applekannaAuthor Commented:
So is typecasting is only used when return type is of object and of other primitive types like char to int is it?

0
 
objectsCommented:
eg. if you have an ArrayList containing Strings':

String s = (String) mylist.get(0);
0
 
applekannaAuthor Commented:
thx for ur help :)
0
 
objectsCommented:
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now