1.日志时间打印StopWatch
public static void main(String[] args) throws InterruptedException {
StopWatchTest.test1();
}
public static void test1() throws InterruptedException {
StopWatch sw = new StopWatch("test");
sw.start("task1");
// do something
Thread.sleep(100);
sw.stop();
sw.start("task2");
// do something
Thread.sleep(200);
sw.stop();
System.out.println("sw.prettyPrint()~~~~~~~~~~~~~~~~~");
System.out.println(sw.prettyPrint());
}
2.初始化list
ArrayList<T> obj = new ArrayList<T>() {{
add(Object o1);
add(Object o2);
...
...
}};
3.字符串拼接
String content = String.format("%s 您好, 您已重置密码, 默认初始密码为:[%s], 请尽快修改密码", sysUser.getUsername(), "password");
4.判断两个list是否有交集
//存在交集flase//不存在true
boolean isNotAdmin = Collections.disjoint(user.getRoleCodes(), UserConstant.ROLE_CODE_LIST);
if (isNotAdmin){
return R.failed("暂无权限");
}
Java编程:StopWatch使用及列表操作示例
本文展示了如何在Java中使用StopWatch进行时间测量,包括开始、停止和打印任务耗时。同时,还演示了初始化ArrayList的快捷方式以及如何进行字符串格式化拼接。此外,文章还涵盖了检查两个list是否有交集的方法,用于权限判断。
112

被折叠的 条评论
为什么被折叠?



