使用 Java 移除字符串中的前导零

给定一串数字,从中删除前导零。

public class Test {
	public static void main(String[] args) {
		String str = "00000123569";
		System.out.println(removeZero(str)); // 123569
		str = "000012356090";
		System.out.println(removeZero(str)); // 12356090
	}

	public static String removeZero(String str) {
		int len = str.length(), i = 0;
		while (i < len && str.charAt(i) == '0') {
			i++;
		}
		return str.substring(i);
	}
}
原文地址:https://www.cnblogs.com/hgnulb/p/11291716.html