猿问

Java 中 JavaScript console.count() 的等价物是什么?

在 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));

}


三国纷争
浏览 170回答 2
2回答

杨魅力

起初,我糊涂了自己console.count()用console.log();根据我的理解,Java 中没有可用的默认功能可以让您知道使用某个参数调用特定方法或函数的次数。但是,您可以实现自定义逻辑,让您这样做。

月关宝盒

标准 API 中没有等效项。你要么自己实现它,要么找到一个提供它的库。
随时随地看视频慕课网APP

相关分类

Java
我要回答