how to fill the left side of a string with zeros

www.la‮c.iruttu‬om
how to fill the left side of a string with zeros
/**
 * @author lautturi.com 
 * Java example: how to pad zero at the left side of a string
 */

import java.util.*;

public class Lautturi {

	public static void main(String[] args) {

		String str = "1234";
		String newStr = String.format("%8s",str)
				.replace(' ', '0');
		System.out.println(str);
		System.out.println(newStr);

	}
}

output:

1234
00001234
Created Time:2017-09-23 21:03:17  Author:lautturi