在 Javascript 中,有一个选项可以使用console.count("ExampleString")打印带有打印计数的字符串。这在通过打印运行时创建的字符串进行调试时非常有用。JAVA 中有这样的东西吗?
编辑:
谢谢你的反对!!
我用 Java 编写了一个片段来实现 console.count 的作用。
final Map<String,Integer> hitCountStore = new HashMap<>();
void countHit( String str )
{
if(hitCountStore.containsKey(str))
{
int var = hitCountStore.get(str).intValue();
hitCountStore.put(str, ++var);
}
else
{
hitCountStore.put(str, 1);
}
System.out.println( str + " >> " + hitCountStore.get(str));
}
杨魅力
月关宝盒
相关分类