Java for循环中设置停顿 逻辑代码中同样适用

 1\ for (Object object : jsonArray) {
  
  2\ Thread.currentThread().sleep(1000);
  
  3\ list.add(((JSONObject)object).get("Name"));
  
  4\ }
  
  此处的停顿 适用于逻辑代码和循环 1000的单位为毫秒
  
  停顿后提示一个未处理的异常
  
  此时需要异常处理 
  
 1\ //抛出异常
  
 2\ throws InterruptedException
  
 3\ //或者try catch操作
  
 4\ try {
  
 5\ Thread.currentThread().sleep(1000);
  
 6\ } catch (InterruptedException e) {
  
 7\ e.printStackTrace();
  
 8\ }
  
9\  ---------------------
  
  作者:超级鸿
  
  来源:CSDN
  
  原文:https://blog.csdn.net/weixin_40195422/article/details/84789856
  
  版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2018-12-06 23:25  画个圈圈诅咒ni  阅读(952)  评论(0编辑  收藏  举报