1 数据类型
1.1 数值类型
1.2 类型转换
1.3 算数运算符
1.4 短路逻辑运算符
1.5 三元运算符
1.6 数据输入
// [1] 导入包
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// [2] 对象
Scanner sc = new Scanner(System.in);
// [3] 输入
int numInput = sc.nextInt();
System.out.println("input num: " + numInput);
}
}
2 分支结构
2.1 if语句
2.2 switch
2.3 for循环
for (int i = 0; i < numInput; i++){
System.out.println("xhh is good [ " + i + " ]");
}
2.4 while
int count = 5;
while (count > 0){
System.out.println(count);
count--;
}
2.5 do-while
int count = 5;
do{
System.out.println(count);
count--;
}while (count > 0);
2.6 跳转控制语句
2.7 Random
2.8 IDEA常用功能
4 数组
4.1 创建数组与初始化
4.2 数组元素访问
int[] arr = {11, 33, 55};
System.out.println(arr.length);
for(int i = 0; i < arr.length; i++){
System.out.println("item -> " + arr[i]);
}
int[][] arr2 = {{11, 55}, {22, 66}};
for(int i = 0; i < arr2.length; i++){
for(int j = 0; j < arr2[0].length; j++){
System.out.println(arr2[i][j] + " ");
}
System.out.println("----");
}
5 方法
5.1 方法的定义和使用
package com.xhhLearn01;
public class xhh01 {
public static void main(String[] args) {
int x = 11, y = 22;
// [2] 方法使用
System.out.println("result: " + getSum(x, y));
}
// [1] 方法定义
public static int getSum(int x, int y) {
return x + y;
}
}
5.2 引用类型
6 面向对象
6.1 类的定义
package com.xhhLearn01;
public class Person {
String name;
int age;
public void showInfo() {
System.out.println("name: " + name + " age: " + age);
}
}
package com.xhhLearn01;
public class Person {
String name;
int age;
public void showInfo() {
System.out.println("name: " + name + " age: " + age);
}
}
6.2 成员变量和局部变量
6.3 封装
6.4 构造方法
package com.xhhLearn01;
public class Person {
String name;
int age;
// 无参构造
Person(){
System.out.println("[1] 无参构造");
}
// 带参构造
Person(String _name, int _age){
this.name = _name;
this.age = _age;
System.out.println("[2] 有参构造");
}
public void showInfo() {
System.out.println("name: " + name + " age: " + age);
}
}
6.4 继承
1 基本格式
package com.xhhLearn02;
public class Animal {
public void infoAll(){
System.out.println("Animal info is here");
}
}
// --------------------------------------------------
package com.xhhLearn02;
public class Cat extends Animal{
}
2 继承中遍历访问特点
3 super
4 方法重写
package com.xhhLearn02;
public class Animal {
public void infoAll(){
System.out.println("Animal info is here");
}
public void call(){
System.out.println("Animal is calling");
}
}
//-----------------------------------------------
package com.xhhLearn02;
public class Cat extends Animal{
@Override
public void call() {
// super.call();
System.out.println("Cat is calling");
}
}
6.5 包和使用
6.6 权限和修饰符
6.7 多态
1 简介
2 抽象类
abstruct
package com.xhhLearn02;
public abstract class Animal {
public abstract void call();
}
package com.xhhLearn02;
public class Cat extends Animal{
@Override
public void call() {
System.out.println("Cat is calling");
}
}
Animal c1 = new Cat();
c1.call();
3 内部类
4
7 常用类
7.1 字符串 String
1 简介
2 构造方法
package com.xhhLearn01;
import java.util.Scanner;
public class xhh01 {
public static void main(String[] args) {
String s1 = new String();
System.out.println(s1);
char[] chs = {'a', 'b', 'c'};
String s2 = new String(chs);
System.out.println(s2);
byte[] bys = {97, 98, 99};
String s3 = new String(bys);
System.out.println(s3);
String s4 = "mcy";
System.out.println(s4);
}
}
3 字符串比较、遍历
4 StringBuilder
package com.xhhLearn01;
import java.util.Scanner;
public class xhh01 {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
sb.append("xhh mcy");
System.out.println("sb.length(): " + sb.length());
System.out.println("sb: " + sb);
sb.reverse();
System.out.println("sb: " + sb);
sb.replace(0, 1, "ppppp");
System.out.println("sb: " + sb);
}
}
7.2 ArrayList
1 简介
2 构造和其他方法
3 常用方法
package com.xhhLearn02;
import java.util.ArrayList;
import java.util.Comparator;
public class array {
public static void main(String[] args) {
System.out.println("hello");
ArrayList<Integer> arrI = new ArrayList<Integer>();
arrI.add(11);
arrI.add(13);
arrI.add(15);
arrI.add(17);
System.out.println("[1] arr: " + arrI + "\tsize(): " + arrI.size());
arrI.remove(2); // 删除指定idx 返回被删除的
System.out.println("[2] arr: " + arrI + "\tsize(): " + arrI.size());
arrI.set(0, 999); // 修改指定idx 返回被修改的
System.out.println("[3] arr: " + arrI + "\tsize(): " + arrI.size());
System.out.println("arrI.get(0): " + arrI.get(0));
}
}
7.3 Math
7.4 System
7.5 Arrays
7.6 基本类型包装类
public class array {
public static void main(String[] args) {
Integer i1 = Integer.valueOf(18);
System.out.println(i1);
Integer i2 = Integer.valueOf("99");
System.out.println(i2);
}
}
7.7 自动装箱和拆箱
8 其他内容
8.1 异常
8.2
8.3
9集合
9.1 Collection
1 简介
package com.xhhLearn02;
import java.util.ArrayList;
import java.util.Collection;
public class array {
public static void main(String[] args) {
// 多态创建
Collection<String> co = new ArrayList<String>();
co.add("xhh");
co.add("mcy");
System.out.println(co);
}
}
2 常用方法
3 遍历
package com.xhhLearn02;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class array {
public static void main(String[] args) {
// 多态创建
Collection<String> co = new ArrayList<String>();
co.add("xhh");
co.add("mcy");
co.add("zph");
// [1] 迭代器遍历
Iterator<String> iter = co.iterator();
while (iter.hasNext()){
String s = iter.next();
System.out.println(s);
}
}
}
9.2 List
1 简介
2 方法
package com.xhhLearn03;
import java.util.ArrayList;
import java.util.List;
public class main {
public static void main(String[] args) {
List<Integer> arrInt = new ArrayList<Integer>();
arrInt.add(11);
arrInt.add(66);
arrInt.add(33);
arrInt.add(0, 33); // 在 idx0处插入33
arrInt.remove(2); // 移除idx2
for(int i = 0; i < arrInt.size(); i++){
System.out.println("item -> " + arrInt.get(i));
}
}
}
3 列表迭代器 ListIterator(了解)
package com.xhhLearn03;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
public class main {
public static void main(String[] args) {
List<Integer> arrInt = new ArrayList<Integer>();
arrInt.add(11);
arrInt.add(66);
arrInt.add(33);
// [1] 正序遍历
ListIterator<Integer> iter = arrInt.listIterator();
while (iter.hasNext()){
int num = iter.next();
System.out.println(num);
}
// [2] 逆序遍历
while (iter.hasPrevious()){
int num = iter.previous();
System.out.println(num);
}
}
}
4 增强for
for(int num: arrInt){
System.out.println(num);
}
5 List子类的特点
6 LinkedList特有功能
9.3 集合Set
1 简介
2 两种遍历
package com.xhhLearn03;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class main {
public static void main(String[] args) {
// 哈希表 查找快
Set<Integer> hset = new HashSet<Integer>();
hset.add(11);
hset.add(99);
hset.add(55);
// 遍历 [1]
Iterator<Integer> iter = hset.iterator();
while (iter.hasNext()){
System.out.println(iter.next());
}
// 红黑树(二叉树 平衡树 查找树)
Set<Integer> tset = new TreeSet<Integer>();
tset.add(111);
tset.add(999);
tset.add(555);
// 遍历 [2]
for(int e: tset){
System.out.println(e);
}
}
}
3 HashSet
4 TreeSet
9.4 泛型
1 泛型类
2 泛型方法
9.5 Map(HashMap & TreeMap)
1 HashMap简介
package com.xhhLearn03;
import java.util.*;
public class main {
public static void main(String[] args) {
Map<Integer, String> map = new HashMap<Integer, String>();
map.put(11, "xhh");
map.put(55, "mcy");
map.put(33, "zph");
System.out.println(map);
System.out.println(map.get(11));
}
}
2 方法
3 获取功能
// 获取所有key
Set<Integer> mapKeys = map.keySet();
// 获取所有value
Collection<String> mapVs = map.values();
4 map的遍历
package com.xhhLearn03;
import java.util.*;
public class main {
public static void main(String[] args) {
// Map<Integer, String> map = new HashMap<Integer, String>();
Map<Integer, String> map = new TreeMap<Integer, String>();
map.put(11, "xhh");
map.put(55, "mcy");
map.put(33, "zph");
System.out.println(map);
// 遍历 1
// 获取所有key
Set<Integer> mapKeys = map.keySet();
for(Integer key: mapKeys){
System.out.println("key: " + key + " value: " + map.get(key));
}
// 遍历 2 获取键值对
Set<Map.Entry<Integer, String>> mapKVs = map.entrySet();
for(Map.Entry<Integer, String> kv: mapKVs){
System.out.println("key: " + kv.getKey() + " value: " + kv.getValue());
}
}
}
9.6 Collections 工具类