The fill() method in the Arrays class is useful for creating string filled with a certain character.
// create a buffer of 9 characters char fill = new char; // Fill the buffer with all '0's Arrays.fill(fill, '0'); // Create string using the buffer String zeroes = new String(fill); // zeroes string now contains "000000000"
2 Responses to “How to fill a String with a character using Java?”
Leave a Reply
You must be logged in to post a comment.