Java API一些注意的零碎不定期整理
2017-06-20 09:03
316 查看
Arrays.binarySearch()
二分搜索是建立在有序数组上的,所以搜索前排序,否则得到的结果不可行。指定from, to的时候,包括from,不包括to
如果查找到返回对应的位置,没有查找到返回第一个比他大的位置,值为负数,转换后为(-res -1)
不管指定区间与否,3都成立。
将集合元素反序
Collections.reverse()
运行时间在线性范围,但是需要开辟额外的空间。
将数组转成字符串,并指定分隔符
APIstatic String join(CharSequence delimiter, CharSequence... elements) Returns a new String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter. static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) Returns a new String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter.
注意这里只能处理字符串数组,对于其他类型的数组不行
对于其他类型的,还没发现好用的,目前只能用Arrays.toString(),再用正则进一步处理
String[] strs = {"1","2","3","4"}; System.out.println(String.join(",", strs)); //1,2,3,4 int[] nums = {1,2,3,4,6,7,8,9}; System.out.println(Arrays.toString(nums).replaceAll("[\\[\\]]", "")); //1, 2, 3, 4, 6, 7, 8, 9
replace replaceAll replaceFirst区别
replace没有用到正则表达式repaceAll和replaceFirst都用到正则表达式
replaceAll是贪心的用法
replaceFirst是懒惰的
相关文章推荐
- C语言零碎的一些注意事项(更新中)
- 整理的一些关于虚函数的使用方法和注意点
- 整理一些常用方法,不定期更新。。。
- 【JAVA】在网上看到的一些题目,在此做一些整理<此贴不定期更新>
- 关于RESTful一些注意事项,和自己整理的接口开发规范
- 一些零碎的整理
- 不定期整理一些常用的函数
- 关于RESTful一些注意事项,和自己整理的接口开发规范
- 本科数学建模时候的一些零碎总结(未整理)
- [置顶] 关于C++中STL的一些东西(不定期整理)
- 整理一些JavaScript的IE和火狐的兼容性注意事项
- 总结的学习php的一些注意点(整理)
- Java的一些注意--随意整理(一)
- 一些前端注意事项整理
- 模电的一些零碎问题,不定期更新
- C语言零碎的一些注意事项(更新中)
- C语言知识点注意事项分类整理[不定期更新]
- go语言,一些零碎没时间整理
- 算法课不定期心得整理——一些递归式的求解心得
- 看别人的代码,整理一些零碎的东西