常用

English

EnglishDemo

面试题

原码、反码、补码
负数的反码是它的原码除符号位,按位取反。
负数的补码等于其反码+1。
正数的反码、补码都是自身;
集合类的转换公共类参考地址
https://blog.csdn.net/sinat_34241861/article/details/106766677

https://juejin.cn/post/6964267379547504648
List
iterator.hasNext()、iterator.next()、iterator.remove()    //Iterator遍历

list的stream流获取的List集合修改时,原集合的值也会随着修改
List分页查询
// 分页参数任务设置不会报错
list.stream().skip((pageNo-1)*pageSize).limit(pageSize).collect(Collectors.toList())
// 获取第一个不存在时不会报错
list.stream().findFirst().orElse(null);
List、json转换
JSON.toJSONString(List<Student>);                           //List转json

JSON.parseObject(json, new TypeReference<List<Obj>>(){});   //Json转List
JSON.parseArray(json, Student.class);
JSON.parseArray(json).toJavaList(Student.class);
List分页
int endRow = pageNo * pageSize;
endRow = NumberUtils.min(endRow, list.size());

int startRow = (pageNo - 1) * pageSize;
startRow = NumberUtils.min(startRow, endRow);

List<T> subList = list.subList(startRow, endRow);
int totalNum = list.size();
数组转Stream流
Stream.of(String[] arr);
stream流转数组
.toArray(String[]::new);
stream二级分组
Collectors.groupingBy(
                Person::getName
                ,Collectors.groupingBy(p->p.getAge()>=18?"成年":"未成年"
                )
结果拼接
collect(Collectors.joining());
// 张三李四张三李四张三

collect(Collectors.joining("_"));
# 张三_李四_张三_李四_张三

collect(Collectors.joining("_", "###", "$$$"));
# 张三_李四_张三_李四_张三$$$
reduce方法
reduce(0, Integer::sum);
reduce(0, (x, y) -> {return x > y ? x : y;});
reduce(0, Student::getAge, (x,y)->x+y);
List、数组转换
String[] arr = list.toArray(new String[list.size()]);       //List转数组
String[] arr = list.stream().toArray(String[]::new);

List<String> list=new ArrayList<>(Arrays.asList(arr));      //数组转List
List<String> list=Stream.of(arr).collect(Collectors.toList());
数组内数据类型转换
int[] productTypes = (int[]) ConvertUtils.convert(productType, int.class);  字符串数组转整形数组
IO流、字符串转换
InputStream is = IOUtils.toInputStream(str);              字符串转IO流
String str = IOUtils.toString(is);                        IO流转字符串
字符串处理
org.apache.commons:commons-lang
StringUtils.replaceChars                                   //一次替换多个字符

java.util.Collections.singletonList("aa")                  //字符串生成集合

List<String> indices = Arrays.asList("abc");               //字符串生成集合
空值处理
Optional.ofNullable(obj).orElse(obj);                      //空值处理
集合处理
#交集
org.apache.commons.collections.ListUtils.intersection(list1, list2);

#差集
org.apache.commons.collections.ListUtils.subtract(list1, list2);

#并集
org.apache.commons.collections.union(list1, list2);

#差集+交集
org.apache.commons.collections.sum(list1, list2);

#比较是否相等
org.apache.commons.collections.isEqualList(list1, list2);

# 交接
org.apache.commons.collections.SetUtils.intersection(set1, set2);
# 差集
org.apache.commons.collections.SetUtils.difference(set1, set2);
# 并集
org.apache.commons.collections.SetUtils.union(set1, set2);

ListUtils.subtract(list1,list2);                             //集合差集
cn.hutool.core.lang.tree.TreeUtil.build(treeNodeList, "0");  //列表生成树目录

//1、两个集合类
List<JSONObject> aClassList1=new ArrayList<>();
List<JSONObject> aClassList2=new ArrayList<>();

//交集
aClassList1.stream().filter(aClassList2::contains)
.collect(Collectors.toList());

//并集
Stream.of(aClassList1,aClassList2).flatMap(Collection::stream)
.distinct().collect(Collectors.toList());

//差集
aClassList1.stream().filter(x->!aClassList2.contains(x))
.collect(Collectors.toList());

//合并为一个List: List<List<List<Apple>>>
List<List<JSONObject>> list = new ArrayList<>();
List<JSONObject> list_1 = list.stream()
.flatMap(List::stream).collect(Collectors.toList());

List<JSONObject> list_2 = list.stream()
.flatMap(a -> a.stream()).collect(Collectors.toList());

//求和
list.stream().flatMapToInt(a ->a.stream().mapToInt(b->b.getNum())).sum();

//分组后取数量
list.stream().collect(Collectors.groupingBy(a->a, Collectors.counting()));
LocalDateTime时间转换为月初、月末方法
LocalDateTime statiDate
statiDate.with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN);
statiDate.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MIN);
流关闭
cn.hutool:hutool-all
cn.hutool.core.io.IoUtil.close(conn);                               关闭流连接
cn.hutool.core.io.IoUtil.copy(in, out)                              流的复制
org.apache.commons.io.IOUtils.copy(int, out)                        流的复制
org.apache.commons.io.IOUtils.closeQuietly(in);                     流的关闭
常用的工具包
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.10.0</version>
</dependency>
常用算法
对称加密算法:AES、DES、3DES、RC、SM1、SM4、SM7
工具
csdn
菜鸟
w3school
属性复制
<dependency>
    <groupId>commons-beanutils</groupId>
    <artifactId>commons-beanutils</artifactId>
    <version>1.9.4</version>
</dependency>
org.apache.commons.beanutils.BeanUtils.copyProperties(source, target);
在1.9.3之前的版本会出现这个异常:
org.apache.commons.beanutils.ConversionException: No value specified for \'Date\'

参考文档:https://blog.csdn.net/u010648555/article/details/108371067
arthas定位问题使用
wget https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar
输入对应项目数字
idea可生成对应方法watch
克隆
BeanUtils.cloneBean(Object obj);BeanUtils.copyProperties(S,T);     浅克隆
SerializationUtils.clone(T object);                                深克隆
获取安全的随机字符串
new SecureRandom().nextInt(10);
csdn可复制的js
javascript:document.body.contentEditable='true';document.designMode='on'; void 0 ; $=0;
文章地址

UML

Design Pattern

Algorithm

posted @   rbcd  阅读(138)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
点击右上角即可分享
微信分享提示