Solved

convert a hashtable to arraylist

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

thx
0
Comment
Question by:applekanna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

728 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