File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes TypeCasting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "TypeCasting" Watch "TypeCasting" New topic


Chinmay Bajikar
Ranch Hand

Joined: Dec 08, 2001
Posts: 159
How heavy is a TypeCasting operation?
Especially when I am doing Object typecasting?
String s = (String)vector.elementAt(0);
is efficient or
String s = vector.elementAt(0).toString();
is efficient.
Thanks in adv,

The strength of the Wolf is the pack & the strength of the pack is the wolf....Rudyard Kipling
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Casting is cheaper than most Method calls, but it has it's own set of problems.
You might want to read Java performance programming, Part 2: The cost of casting from JavaWorld

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: TypeCasting
It's not a secret anymore!