ascii code -> String conversion

G

Gergely Buday

Hi folks,

is there an easier way to convert an ascii code to a String than the
method used in this tiny program?

public class Main {

public static void main(String[] args) {
for (int i = 65; i < 91; i++)
{
byte[] bytes = new byte[1];
bytes[0] = (byte) i;
String letter = new String(bytes);
System.out.print(letter);
}
System.out.print("\n");
}
}

- Greg
 
G

Gordon Beaton

is there an easier way to convert an ascii code to a String than the
method used in this tiny program?

public class Main {

public static void main(String[] args) {
for (int i = 65; i < 91; i++)
{
byte[] bytes = new byte[1];
bytes[0] = (byte) i;
String letter = new String(bytes);
System.out.print(letter);
}
System.out.print("\n");
}
}

- Greg

chars are integers too:

for (char c = 'a'; c <= 'z'; c++) {
System.out.print(c);
}
System.out.println();

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top