File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Casting problem of Arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Casting problem of Arraylist" Watch "Casting problem of Arraylist" New topic
Author

Casting problem of Arraylist

garfild Baram
Ranch Hand

Joined: Mar 24, 2003
Posts: 60
Hi,
I have an Arraylist that contains hashtables, trying to retrieve those hashtable using:
Hashtable hash=null;
hash = (Hashtable)arr(0);
I get ClassCastException (although the compilation goes well).
How do I cast an Arraylist to get my hashpapies??
Thanks
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1675
Moving this thread from the Cattle Drive forum to Java in General (intermediate) because it doesn't seem connected to any of the Cattle Drive assignments.
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1675
What does "arr(0)" do? What type does it return?
garfild Baram
Ranch Hand

Joined: Mar 24, 2003
Posts: 60
All objects in the ArrayList are Hashtable type and arr(0) should return first Hashtable inserted.
Stefan Zoerner
Author
Ranch Hand

Joined: Nov 29, 2001
Posts: 121
Hello!
I do not understand yout expression arr(0) as well. Is it possible to post more line of code?
Other option: Does it look like this:

This one works. Greetings from Hamburg,
Stefan


Stefan Zoerner
Author of German LDAP-Book
Committer at Apache Directory Project
garfild Baram
Ranch Hand

Joined: Mar 24, 2003
Posts: 60
Thanks Stefan and Michael,
Stupid mistake in my code and it works fine now,
Thanks again mates.....
 
 
subject: Casting problem of Arraylist
 
Threads others viewed
Passing object to excel spreadsheet
Hashtable and vector Problem in Servlet
Numbering Objects
ArrayList and Vector
about hashmap implementation of arraylist
IntelliJ Java IDE