1     private static boolean checkIfExistChineseCharacter(String s) {
2         return !(s.length() == s.getBytes().length);
3     }

 

 

网上看到的写法,真的是机智。当然可能有一些细节问题:UTF-8编码中不是ascii码的都会长度不一致。但是感觉还是机智的不行。

 

补充:事后测试了效率,在1千万行的情况下,用一个for循环会快3秒。for循环用时815ms,getBytes用时3722ms。在效率要求不是特别高的情况下,getBytes还是可以使用的。

相关文章:

  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2021-08-20
  • 2021-07-28
相关资源
相似解决方案