Java java.util.logging.logger.使用数组对象作为参数 [英] Java java.util.logging.logger. Using array objects as arguments
问题描述
java.util.logging.Logger类提供使用这种语法的能力:
java.util.logging.Logger class provides ability to use such a syntax:
int i=0;
log.log(Level.INFO,"int i = {0}", i);
这将打印出"int i = 0".不幸的是,当我有一个较大的值(如9093)时,它将打印出"int i = 9,023",每三个数字之间用逗号分隔.
This will print out "int i = 0". Unfortunately when I have a bigger value, like 9093, it will print out "int i= 9,023" separating each 3 digits with comma.
问题是我应该如何去除小写逗号?最好更改{}的内部.尝试了{0:d}和{0:%d}.两者都没有帮助.甚至可以像这样控制参数吗?还是我应该将自己的int转换为字符串?
The question is how should I get rid of thoose commas? Preferably changing insides of {}. Tried both {0:d} and {0:%d}. Both didnt help. Is it even possible to control parametres like this? Or should I convert my int to string myself?
推荐答案
似乎第二个参数是MessageFormat
,它支持子格式".试试
It seems the second parameter is a MessageFormat
which supports "sub-formats". Try
log.log(Level.INFO, "int i = {0,number,#}", 1234567);
这消除了我对字符的分组.
This eliminates grouping characters for me.
请参见 http://docs.oracle.com /javase/7/docs/api/java/text/MessageFormat.html 和
See http://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html and http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html (number sub-formats are interpreted as DecimalFormat
).
这篇关于Java java.util.logging.logger.使用数组对象作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!