文章图片资料来源黑马程序员java视频课程,仅供个人学习参考。
static关键字
工具类
代码块
单例模式
继承
包
权限修饰符
final
常量
枚举
抽象
接口
多态
类型转换问题
内部类
public class People {
private int heartbeat = 150;
//成员内部类
public class Heart{
private int heartbeat = 110;
public void show(){
int heartbeat = 70;
System.out.println(heartbeat);
System.out.println(this.heartbeat);
System.out.println(People.this.heartbeat);
}
}
}
匿名内部类
常用API
StringBuilder
Math类
System
BigDecimal
Date
Calendar
Java.time
包装类
正则表达式
Array类
package com.itheima.ArrayTest;
import java.util.Arrays;
import java.util.Comparator;
public class ArrayTest {
public static void main(String[] args) {
// 自定义排序中必须为引用对象 因此这里不是int 而是Integer
Integer[] ages = {10,15,23,78,58};
Arrays.sort(ages, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
//降序排序
if (o1 > o2){
return -1;
}else if(o1 < o2){
return 1;
}
return 0;
}
});
System.out.println(Arrays.toString(ages));
}
}
package com.itheima.ArrayTest;
import java.util.Arrays;
public class SortTest {
public static void main(String[] args) {
int[] test = {16,18,20,23,26};
int[] test1 = {20};
chooseSort(test);
System.out.println(BinarySort(test,18));
}
//二分查找
private static int BinarySort(int[] test, int query) {
int min = 0;
int max = test.length - 1;
int index = (min + max)/2;
while (min <= max){
if (test == null){
return -1;
}
if (test[index]==query){
return index;
}else if (test[index]< query){
//在右边查找
min = index + 1;
// index = (min + max)/2;
}else {
//左边查找
max = index - 1;
// index = (min + max)/2;
}
}
//比较i位置的值
return -1;
}
//选择排序算法
private static void chooseSort(int[] test) {
if (test == null){
System.out.println("空");
}
// int min = test[0];
for (int i = 0; i < test.length; i++) {
for (int j = i+1; j < test.length; j++) {
if (test[j]<test[i]){
int temp = test[j];
test[j] = test[i];
test[i] = temp;
}
}
}
System.out.println(Arrays.toString(test));
}
//
}
Lambda
package com.itheima.Lambda;
public class LambdaTest {
public static void main(String[] args) {
//必须是函数式接才可以简化 匿名内部类的写法
// Swimming s = new Swimming() {
// @Override
// public void swim() {
// System.out.println("学生游泳很厉害🏊");
// }
// };
Swimming s = () -> {
System.out.println("学生游泳很厉害🏊");
};
go(s);
}
public static void go(Swimming s){
System.out.println("开始");
s.swim();
System.out.println("结束");
}
}
@FunctionalInterface
interface Swimming {
void swim();
}
集合
package com.itheima.Collection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;
public class IteratorTest {
public static void main(String[] args) {
Collection<String> list = new ArrayList<>();
list.add("23");
list.add("tess");
list.add("sdasdas");
//1.迭代器遍历
// Iterator<String> it = list.iterator();
// while (it.hasNext()){
// String e = it.next();
// System.out.println(e);
// }
//2.增强for循环便利
// for (String ele: list) {
// System.out.println(ele);
//
// }
//3.Lambda表达式遍历
// list.forEach(new Consumer<String>() {
// @Override
// public void accept(String s) {
// System.out.println(s);
// }
// });
list.forEach((String s) -> {
System.out.println(s);
});
}
}
Set
可变参数
Map
package com.itheima.Map;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
public class MapTest {
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<>();
map.put("java1",1);
map.put("java2",1);
map.put("java3",3);
//第一种遍历
//获取键值集合
// Set<String> keys = map.keySet();
// for (String key : keys){
// int value = map.get(key);
// System.out.println(value);
// }
//第二种方式
// Set<Map.Entry<String, Integer>> entries = map.entrySet();
// for (Map.Entry<String, Integer> entry: entries) {
// System.out.println(entry.getKey());
// System.out.println(entry.getValue());
//
// }
//第三种方式
map.forEach(new BiConsumer<String, Integer>() {
@Override
public void accept(String key, Integer value) {
System.out.println(key+"====>"+value);
}
});
}
}
Stream
异常
日志技术