Java常用归纳1.0

1.数组排序:

Arrays.sort(arr);

2.类型转换:

(1)Int转char:
String numStr = String.valueOf(num);

(2)char转Int:


(3)char转String:
String str1 = new String(chars);
String str2 = String.valueOf(chars);

(4)String转char:
char[] chars1 = str.toCharArray();

(5)Int转String:
String MyString = "" + num;

(6)String转Int:
​Integer.parseInt(string);

3.去重:

(1)List去重:

HashSet去重:
//List<Integer> list = new ArrayList<Integer>();
List<Integer> ans = new ArrayList<Integer>();
HashSet set = new HashSet(list);
ans.addAll(set);

4.获取长度:

(1)获取数组长度:
arr.length;

(2)获取字符串长度:
s.length();

(3)获取集合长度:
c.size();

5.数学方法:

(1)取最大值:
Math.max(a,b);

(2)取最小值:
Math.min(a,b);

(3)取绝对值:
Math.abs(c);

(4)e的a次方:
Math.exp(a);

(5)ln(b)的值:
Math.log(b);

(6)根号d:
Math.sqrt(d);

(7)h的立方根:
Math.cbrt(h);

(8)f的b次方:
Math.pow(f,g);

6.列表List用法: 

(1)创建一个列表
List<Object> list  = new ArrayList<Obect>();

(2)添加指定对象
list.add(int index,Object obj);

(3)添加所有对象
list.addAll(int,Collection coll);

(4)清除指定对象
list.remove(int index);

(5)修改集合指定索引位置对象为指定对象
list.set(int index,Object obj);

(6)获得指定对象的索引位置(存在多个时,返回第一个)
list.get(int index);

(7)获得指定对象的索引位置(存在多个时,返回最后一个)
list.indexOf(Object obj);

(8)获得包含所有对象的ListIterator型实例
list.listIteration();

(9)获得包含指定位置到最后的ListIterator型实例
list.listIteration(int index);

(10)截取列表
list.subList(int fromIndex,int toIndex);

(11)反转顺序
list.reverse(List list);

(12)对List集合元素进行随机排序
list.shuffle(List list)j;

(13)默认升序排序
list.sort(List list);

(14)根据指定Comparator产生的顺序对List集合的元素进行排序
list.sort(List list,Comparator c);

(15)将指定List集合中i处元素和j处元素进行交换
swap(List list,int i,int j);

(16)将集合中的元素旋转
static void rotate(List list,int distance);

(17)判断集合中是否含有某元素
list.contains(Object obj);

7.栈Stack用法:

(1)创建一个空栈
Stack stack = new Stack();

(2)测试栈是否为空
stack.empty();

(3)查看栈顶部的对象,但不从栈中移除它
stack.peek();

(4)移除栈顶部的对象,并作为此函数的值返回该对象
stack.pop();

(5)把项压入栈顶部
stack.push(Object element);

(6)返回对象在栈中的位置,以 1 为基数
stack.search(Object element);

(7)用栈Stack 创建对象(类型不同)
Stack stack = new Stack<>();

8.双队列Deque用法:

(1)构造:
Deque<Object> path = new ArrayDeque<>();

(2)增加:
path.addLast(Object obj);

(3)删除:
path.removeLast();

(4)遍历:

(5)判断:

(6)大小:

(7)其他:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hokachi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值