tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Caldarale, Charles R" <Chuck.Caldar...@UNISYS.com>
Subject RE: off topic - how do i convert an int to char
Date Tue, 07 Dec 2004 16:21:21 GMT
> From: Parsons Technical Services [mailto:parsonstechnical@earthlink.net]
> Subject: Re: off topic - how do i convert an int to char
> 
> Cast it with the offset added.
> int i = 0;
> char ch = (char)(i+97);

Or if you want to make it a little more understandable:

    char ch = (char) (i + 'a');

Note that the previously suggested use of the substring() method has two drawbacks: it returns
a String, not a char as originally requested; and it creates a new String object every time
it's called.  Both problems would be avoided by using charAt() rather than substring().  Still
not as fast as the straight arithmetic shown above.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus
for use only by the intended recipient. If you received this in error, please contact the
sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message