«««< HEAD
layout: post
title: “java”
subtitle: “ "java"”
date: 2021-05-25 18:00:00
author: “zwt”
header-img: “img/post-bg-2015.jpg”
catalog: false
tags:
- 开发语言
—
基础知识
String
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| 转list
Arrays.asList(strs.split(""))
互转char
String.toCharArray()转化为char[]
String.valueOf('c')
转Long
Long.valueOf("String")返回Long包装类型
Long.parseLong("String")返回long基本数据类型
//创建数组与集合
String[] string=new String[5];
ArrayList<String> list = new ArrayList<String>();
//把数组转成集合,也就是把数组里面的数据存进集合;
Collections.addAll(list, string);
判别相等:s1.equals(s2)
|
list:List的父接口是Collection,ArrayList是List的子接口
1
2
3
4
5
6
7
8
| 去重
list.stream().distinct().collect(Collectors.toList())
创建
List<String> list = new ArrayList<String>();
List<Stirng> list = Lists.newArrayList();
为空
null == list || list.size() ==0
list.isEmpty()
|
获取当前路径
1
| System.out.println(System.getProperty("user.dir"));
|
hashmap
1
2
3
4
| 遍历
Map<String, String> map = new HashMap<String, String>();
for (String key : map.keySet()) {
map.get(key);}
|
遍历Collection
1
2
3
4
5
| Iterator<String> it = array.iterator();
while (it.hasNext()) {
String s = it.next();
System.out.println(s);
}
|
时间计算问题
1
2
3
4
5
6
7
| // 当前时间前一天
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance(); //创建Calendar 的实例
calendar.setTime(d);
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1);
String endDate = sdf.format(calendar.getTime());
|
java判断list是否为空
1
2
| 结论:list!=null&&!list.isEmpty()
list.isEmpty()判断是是其中的size是否为0
|
类型互转
1
2
3
4
| 不四舍五入
(int) x
四舍五入
Integer.parseInt(new java.text.DecimalFormat("0").format(x))
|
集合
1
2
3
4
5
| 1.打乱Collections.shuffle(list);
2.反转Collections.reverse(list);
3.交集CollectionUtils.intersection(listA, listB)
4.并集CollectionUtils.union(listA, listB)
5.差集CollectionUtils.subtract(listA, listB)
|
map初始化:
1
| HashMap<String, String > myMap = new HashMap<String, String>();
|
类型转换
1
2
| 1.string转integer:Integer.parseInt(String str)
2.HashMap hashMap = JSON.parseObject(str, HashMap.class);
|
定时任务
1
2
3
4
5
6
7
| 1.秒 0-59 , - * /
2.分钟 0-59 , - * /
3.小时 0-23 , - * /
4.日期 1-31 , - * ? / L W C
5.月份 1-12 , - * /
6.星期 1-7 , - * ? / L C #
7.年(可选) 空值1970-2099 , - * /
|
一些示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| 0 0 10,14,16 * * ? 每天上午10点,下午2点,4点
0 0/30 9-17 * * ? 朝九晚五工作时间内每半小时
0 0 12 ? * WED 表示每个星期三中午12点
"0 0 12 * * ?" 每天中午12点触发
"0 15 10 ? * *" 每天上午10:15触发
"0 15 10 * * ?" 每天上午10:15触发
"0 15 10 * * ? *" 每天上午10:15触发
"0 15 10 * * ? 2005" 2005年的每天上午10:15触发
"0 * 14 * * ?" 在每天下午2点到下午2:59期间的每1分钟触发
"0 0/5 14 * * ?" 在每天下午2点到下午2:55期间的每5分钟触发
"0 0/5 14,18 * * ?" 在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发
"0 0-5 14 * * ?" 在每天下午2点到下午2:05期间的每1分钟触发
"0 10,44 14 ? 3 WED" 每年三月的星期三的下午2:10和2:44触发
"0 15 10 ? * MON-FRI" 周一至周五的上午10:15触发
"0 15 10 15 * ?" 每月15日上午10:15触发
"0 15 10 L * ?" 每月最后一日的上午10:15触发
"0 15 10 ? * 6L" 每月的最后一个星期五上午10:15触发
"0 15 10 ? * 6L 2002-2005" 2002年至2005年的每月的最后一个星期五上午10:15触发
"0 15 10 ? * 6#3" 每月的第三个星期五上午10:15触发
|
执行时间
1
2
3
4
5
6
7
| //初始时间
long startTime = System.currentTimeMillis();
/*要计算的程序部分*/
//结束时间
long endTime = System.currentTimeMillis();
//打印
System.out.println("程序运行时间:" + (endTime - startTime) + "ms");
|
maven
查看包依赖关系,包括间接依赖
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| mvn dependency:tree>temp/tree.txt
=======
---
layout: post
title: "java"
subtitle: " \"java\""
date: 2021-05-25 18:00:00
author: "zwt"
header-img: "img/post-bg-2015.jpg"
catalog: false
tags:
- 开发语言
---
* TOC
{:toc}
# 基础知识
String
|
转list
Arrays.asList(strs.split(“”))
互转char
String.toCharArray()转化为char[]
String.valueOf(‘c’)
转Long
Long.valueOf(“String”)返回Long包装类型
Long.parseLong(“String”)返回long基本数据类型
//创建数组与集合
String[] string=new String[5];
ArrayList list = new ArrayList();
//把数组转成集合,也就是把数组里面的数据存进集合;
Collections.addAll(list, string);
判别相等:s1.equals(s2)
1
| list:List的父接口是Collection,ArrayList是List的子接口
|
去重
list.stream().distinct().collect(Collectors.toList())
创建
List list = new ArrayList();
List list = Lists.newArrayList();
为空
null == list || list.size() ==0
list.isEmpty()
System.out.println(System.getProperty(“user.dir”));
遍历
Map<String, String> map = new HashMap<String, String>();
for (String key : map.keySet()) {
map.get(key);}
Iterator it = array.iterator();
while (it.hasNext()) {
String s = it.next();
System.out.println(s);
}
1
2
3
4
5
6
7
8
9
| 时间计算问题
```java
// 当前时间前一天
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance(); //创建Calendar 的实例
calendar.setTime(d);
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1);
String endDate = sdf.format(calendar.getTime());
|
java判断list是否为空
1
2
| 结论:list!=null&&!list.isEmpty()
list.isEmpty()判断是是其中的size是否为0
|
类型互转
1
2
3
4
| 不四舍五入
(int) x
四舍五入
Integer.parseInt(new java.text.DecimalFormat("0").format(x))
|
集合
1
2
3
4
5
| 1.打乱Collections.shuffle(list);
2.反转Collections.reverse(list);
3.交集CollectionUtils.intersection(listA, listB)
4.并集CollectionUtils.union(listA, listB)
5.差集CollectionUtils.subtract(listA, listB)
|
map初始化:
1
| HashMap<String, String > myMap = new HashMap<String, String>();
|
类型转换
1
2
| 1.string转integer:Integer.parseInt(String str)
2.HashMap hashMap = JSON.parseObject(str, HashMap.class);
|
定时任务
1
2
3
4
5
6
7
| 1.秒 0-59 , - * /
2.分钟 0-59 , - * /
3.小时 0-23 , - * /
4.日期 1-31 , - * ? / L W C
5.月份 1-12 , - * /
6.星期 1-7 , - * ? / L C #
7.年(可选) 空值1970-2099 , - * /
|
一些示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| 0 0 10,14,16 * * ? 每天上午10点,下午2点,4点
0 0/30 9-17 * * ? 朝九晚五工作时间内每半小时
0 0 12 ? * WED 表示每个星期三中午12点
"0 0 12 * * ?" 每天中午12点触发
"0 15 10 ? * *" 每天上午10:15触发
"0 15 10 * * ?" 每天上午10:15触发
"0 15 10 * * ? *" 每天上午10:15触发
"0 15 10 * * ? 2005" 2005年的每天上午10:15触发
"0 * 14 * * ?" 在每天下午2点到下午2:59期间的每1分钟触发
"0 0/5 14 * * ?" 在每天下午2点到下午2:55期间的每5分钟触发
"0 0/5 14,18 * * ?" 在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发
"0 0-5 14 * * ?" 在每天下午2点到下午2:05期间的每1分钟触发
"0 10,44 14 ? 3 WED" 每年三月的星期三的下午2:10和2:44触发
"0 15 10 ? * MON-FRI" 周一至周五的上午10:15触发
"0 15 10 15 * ?" 每月15日上午10:15触发
"0 15 10 L * ?" 每月最后一日的上午10:15触发
"0 15 10 ? * 6L" 每月的最后一个星期五上午10:15触发
"0 15 10 ? * 6L 2002-2005" 2002年至2005年的每月的最后一个星期五上午10:15触发
"0 15 10 ? * 6#3" 每月的第三个星期五上午10:15触发
|
执行时间
1
2
3
4
5
6
7
| //初始时间
long startTime = System.currentTimeMillis();
/*要计算的程序部分*/
//结束时间
long endTime = System.currentTimeMillis();
//打印
System.out.println("程序运行时间:" + (endTime - startTime) + "ms");
|
maven
查看包依赖关系,包括间接依赖
1
2
| mvn dependency:tree>temp/tree.txt
>>>>>>> d5005ecd9eaf3ce32260dc1b7d831c7f2a1a85f3
|