Re: Which of these is better casting or toString()
- From: Andrea Desole <news@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 24 Feb 2006 13:52:26 +0100
keshawra wrote:
List lst = new ArrayList();
lst.add("a");
// more add statements here..
((String) lst.get(j)).toUpperCase()
lst.get(j).toString().toUpperCase();
casting or toString() ?? which one is better to use.
kiri
I would cast, because it makes it clear that you are expecting a string. With a cast it's easier to detect an error, with toString() it isn't.
As to performance I'm not sure there is a big difference. I wouldn't be surprised if it depended on the implementation. It shouldn't have a great impact anyway: probably the execution of toUpperCase() takes much longer
.
- References:
- Which of these is better casting or toString()
- From: keshawra
- Which of these is better casting or toString()
- Prev by Date: Converting Java projects to dynamic web projects in Eclipse
- Next by Date: Re: Declaring local variables inside loop
- Previous by thread: Re: Which of these is better casting or toString()
- Next by thread: Re: Which of these is better casting or toString()
- Index(es):
Relevant Pages
|
Loading