Solved

convert a hashtable to arraylist

Posted on 2003-12-09
7
4,601 Views
Last Modified: 2007-12-19
Hi ,
Can I convert a HashTable to an ArrayList

thx
0
Comment
Question by:applekanna
  • 4
  • 3
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 9909825
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
 
LVL 3

Author Comment

by:applekanna
ID: 9909858
One question what is the differnce between

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

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

Thx
0
 
LVL 92

Expert Comment

by:objects
ID: 9909880
> 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 3

Author Comment

by:applekanna
ID: 9910038
So is typecasting is only used when return type is of object and of other primitive types like char to int is it?

0
 
LVL 92

Expert Comment

by:objects
ID: 9910092
eg. if you have an ArrayList containing Strings':

String s = (String) mylist.get(0);
0
 
LVL 3

Author Comment

by:applekanna
ID: 9910108
thx for ur help :)
0
 
LVL 92

Expert Comment

by:objects
ID: 9910116
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate example issues from command prompt 10 50
Is there a simpler dropbox system? 10 34
Java syntax, or is it Selenium 6 30
hashmap order 17 36
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question