这个问题在这里已经有了答案:Whichisbetter/moreefficient:checkforbadvaluesorcatchExceptionsinJava(11个答案)关闭9年前。我见过两种在Java中检查变量是否为有效整数的样式。一种方法是执行Integer.parseInt并捕获任何由此产生的异常。另一种是使用模式。以下哪种方法更好?StringcountStr;intcount;try{count=Integer.parseInt(countStr);}catch(Exceptione){//returnasthevariableisnotaproperinteger.