等待多线程完成的CountDownLatch countDownLatch允许一个或多个线程等待其他线程完成操作. public class CountDownLatchTest { static CountDownLatch countDownLatch = new CountDownLatch(2); public static void main(String[] args) throws InterruptedException{ new Thread(new Runnable() {…
1.使用 MessageFormat 格式化文本 int planet = 7; String event = "a disturbance in the Force"; String result = MessageFormat.format( "At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.", planet, new Date(), event); The output…
在工作中经常遇到需要加密.解密的场景.例如用户的手机号等信息,在保存到数据库的过程中,需要对数据进行加密.取出时进行解密. public class DEStool { private String sKey; public DEStool() { //默认构造函数提供默认密钥 sKey = "des@#$12"; } public DEStool(String securityKey) { ) { throw new IllegalArgumentException("密钥…