I have this program:
public class Duplicates {
public static void main(String[] args) {
byte[] bytes = "hz".getBytes();
for (int i = 0; i < 10_000_000; i++) {
System.out.write(bytes, 0, bytes.length);
}
}
}
After start I have output:
hzhzhzhzhzhzhzhz.....hz
But if I try convert int
to byte array and print:
public class Duplicates {
public static void main(String[] args) {
byte[] bytes = ByteBuffer.allocate(4).putInt(666).array();
for (int i = 0; i < 10_000_000; i++) {
System.out.write(bytes, 0, bytes.length);
}
}
}
After start I have output:
� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �
I want to print 666
10,000,000 times on each line of console and not use more than 20MB memory or 1 second.
What am I doing wrong?
EDIT If I will use example @Justin - Integer.toString(i).getBytes()
I have this: