PS:后续添加 没有顺序了 搜到什么看什么吧
查找子串
public static void main(String[] args) {
String s = "1234567890";
int pos1 = s.indexOf("23");
int pos2 = s.indexOf("A");
System.out.println(pos1); // 1
System.out.println(pos2); // -1
}
数据初始化
int []a = new int[10];
Arrays.fill(a,10);
Arrays.stream(a).forEach(System.out::println);
最大公约数
//公倍数 两数相乘 除以公约数
#include<bits/stdc++.h>
using namespace std;
int a[40] = {1,2};
int main()
{
cout << __gcd(12,6);
//cout << __INT32_MAX__ << endl;
}
1.accumulate求和
public static void main(String[] args) {
int []a = new int[10];
Arrays.fill(a,10);
Arrays.stream(a).sum();
Arrays.stream(a).forEach(System.out::println);
}
4. bitset
可实现十进制和二进制的互换
Integer a= 16;
Integer.toHexString(a);
```c
### 5.copy
```c
int []a = new int[]{12,3,4,5,6};
int[] ints = Arrays.copyOfRange(a, 1, 3);
Arrays.stream(ints).forEach(System.out::println);
6. count
int []a = new int[]{12,3,4,3,6};
long count = Arrays.stream(a).filter(o -> o == 3).count();
System.out.println(count);
9 find
public static void main(String[] args) {
int []a = new int[]{1,2,3,4,5};
int i = Arrays.binarySearch(a, 4);
System.out.println(i);
}
14.replace_if() 满足条件的替换
String s = "12345";
String c = s.replace('4', 'C');
System.out.println(c);
15.strstr() char*类型找到子串
String s = "12345";
int i = s.indexOf("34");
System.out.println(i);
16. substr() 截取字符
String s = "12345";
String substring = s.substring(0, 4);
19. 去重复unique() 必须已经排序
Integer []a = new Integer[]{1,2,3,4,5,5};
List<Integer> collect = Arrays.stream(a).distinct().collect(Collectors.toList());
collect.forEach(System.out::println);
交并集
Integer []a = new Integer[]{1,2,3};
Integer []b = new Integer[]{3,4,5};
HashSet hashSetA = new HashSet<>(List.of(a));
HashSet hashSetB = new HashSet<>(List.of(b));
// hashSetA.retainAll(hashSetB); 交集
// hashSetA.addAll(hashSetB); 并集
// hashSetA.removeAll(hashSetB); 差集
hashSetA.forEach(System.out::println);
得到最大值最小值
ArrayList<Integer> ints = new ArrayList<>(Arrays.asList(1,2,3,4,5,6)) ;
Optional<Integer> max = ints.stream().max((a, b) -> {
return a.compareTo(b);
});
System.out.println(max.get());