java中指定位数,不足的在前面补“0”,用于拼接RowKey

问题描述:查询Hbase时,使用RowKey查询效率会很高,但有时候在已知RowKey由哪几部分字段组成时,会有拼接字符串为RowKey到hbase查询的场景。但是RowKey设计为每段位固定的长高度,不足的需要补“0”。所以,在java程序中,需要调用函数设置固定位数,并用“0”补足。

比如将一位的int“2”,处理成四位的“0002”字符串:

	public static void main(String[] args) {
		 int str=2;
         DecimalFormat df=new DecimalFormat("0000");
         System.out.println(df.format(str));
	}

0002
参考地址: https://blog.csdn.net/weimeng1991/article/details/42964715

猜你喜欢

转载自blog.csdn.net/henrymrz/article/details/80503479