Re: Converting char(s) into String
- From: Thomas Hawtin <usenet@xxxxxxxxxxxxxxxxx>
- Date: Thu, 08 Jun 2006 19:40:49 +0100
John O'Conner wrote:
ponga wrote:String str = "" + s1.charAt(0) + s1.charAt(5);
Maybe a less confusing way to do this is this:String str = strBuff.toString();
StringBuffer strBuf = new StringBuffer();
strBuff.append(s1.charAt(0));
strBuff.append(s1.charAt(5));
One thing to be aware of is that passing a char to the constructor does not do what you may expect.
String str =
new StringBuilder(s1.charAt(0)).append(s2.charAt(5)).toString();
You don't need to go through StringBuffer (or better StringBuilder) for something this simple.
String str = String.valueOf(new char[] { s1.charAt(0), s1.charAt(5) });
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.
- Follow-Ups:
- Re: Converting char(s) into String
- From: amitdev
- Re: Converting char(s) into String
- References:
- Converting char(s) into String
- From: ponga
- Re: Converting char(s) into String
- From: John O'Conner
- Converting char(s) into String
- Prev by Date: Re: automatic number plate recognition
- Next by Date: connecting J2SE application to a servlet
- Previous by thread: Re: Converting char(s) into String
- Next by thread: Re: Converting char(s) into String
- Index(es):
Relevant Pages
|