tags:

views:

138

answers:

2

Right now I'm using the following to minimize boxed object creation:

String myString = "" + myChar;

Is this the idiomatic way to do it? (IMHO it feels a little awkward.)

+4  A: 

String.valueOf(char) or Character.toString(char) (the latter calling the former)

Bozho
+7  A: 

String.valueOf is your friend:

  • It works for every type so you can be consistent
  • It's null-safe (for reference types)
  • It says what you mean

I have a very short article on this subject, in fact.

Jon Skeet
And you won the race by two seconds... the Java tag sure is fast-moving!
cdleary
This one has the nicer explanation too :)
Carl Smotricz