[英]Fastest way to format a String using concatenation and manipulation
String temp = "";
temp = String.format("%02d", ""+hour)+":"+String.format("%02d", ""+min)+":"+String.format("%02d", ""+sec);
Is this the fastest way to format the numbers with concatenation to specify leading zeroes, or is there another way? 这是最快的用级联格式化数字以指定前导零的方法,还是还有另一种方法?
I have to display the String in the format 00:00:00. 我必须以00:00:00的格式显示字符串。 The hour, min, and sec are int variables which start from 0 and are put into the Thread which counts the time elapsed and displays this time accordingly.
hour,min和sec是从0开始的int变量,它们被放入Thread中,该Thread对经过的时间进行计数并相应地显示该时间。 Is this the correct way, or is there any better way?
这是正确的方法,还是有更好的方法?
Try this. 尝试这个。 I assume that hour, min and sec are ints.
我认为小时,分钟和秒都是整数。
String temp = "";
temp = String.format("%02d:%02d:%02d", hour, min, sec);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.