English
EnglishDemo
面试题
原码、反码、补码
负数的反码是它的原码除符号位,按位取反。
负数的补码等于其反码+1。
正数的反码、补码都是自身;
集合类的转换公共类参考地址
https://blog.csdn.net/sinat_34241861/article/details/106766677
https://juejin.cn/post/6964267379547504648
List
iterator.hasNext ()、iterator.next ()、iterator.remove ()
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 >);
JSON .parseObject (json, new TypeReference <List <Obj >>(){});
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 ()]);
String [] arr = list.stream ().toArray (String []::new );
List <String > list=new ArrayList <>(Arrays .asList (arr));
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" );
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<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)
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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)