一 Java基础知识
1.01 数组
package com.test.testfan; public class testfan_01_01_数组 { /** * @param args */ public static void main(String[] args) { // TODO 自动生成的方法存根 int[] a = new int[]{33, 33,3, 44}; System.out.println(a[0]); System.out.println(a.length); System.out.println(a[a.length-1]);//获取最后位数据 /*for (int i = 0; i < a.length; i++) { int j = a[i]; System.out.println(j); }*/ int[] b = new int[100]; b[0] = 1; b[1] = 1; b[2] = 1; b[3] = 1; b[4] = 1; System.out.println(b.length); } }
1.02 集合
package com.test.testfan; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class testfan_01_02_集合 { public static void main(String[] args) { // TODO 自动生成的方法存根 List<String> list = new ArrayList<String>(); list.add("200"); String valueString = list.get(0); System.out.println(valueString); System.out.println(list.size());//类属性 //System.out.println(list.);//类属性 //通过数组 for (int i = 0; i < args.length; i++) { String string = args[i]; } List<Integer> list2 = new ArrayList<Integer>(); list2.add(200); int value2 = list2.get(0); for (int i = 0; i < args.length; i++) { String string = args[i]; System.out.println(string); } //通过集合 for (Iterator iterator = list2.iterator(); iterator.hasNext();) { Integer integer = (Integer) iterator.next(); System.out.println(integer); } //通过数组 for (int i = 0; i < args.length; i++) { } //通过迭代器 for (Integer integer : list2) { System.out.println(integer); } } }
package com.test.testfan; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class testfan_01_02_集合 { public static void main(String[] args) { // TODO 自动生成的方法存根 List<String> list = new ArrayList<String>(); list.add("200"); String valueString = list.get(0); System.out.println(valueString); System.out.println(list.size());//类属性 //System.out.println(list.);//类属性 //通过数组 for (int i = 0; i < args.length; i++) { String string = args[i]; } List<Integer> list2 = new ArrayList<Integer>(); list2.add(200); int value2 = list2.get(0); for (int i = 0; i < args.length; i++) { String string = args[i]; System.out.println(string); } //通过集合 for (Iterator iterator = list2.iterator(); iterator.hasNext();) { Integer integer = (Integer) iterator.next(); System.out.println(integer); } //通过数组 for (int i = 0; i < args.length; i++) { } //通过迭代器 for (Integer integer : list2) { System.out.println(integer); } // 数组属性使用 List<Integer> list3 = new ArrayList<Integer>(); if(!list3.isEmpty()) { int list4 = list3.get(0); System.out.println(list4); } list3.add(200); } }
1.03 对象
package com.test.testfan; public class Person { public String name; public int age; private double money=1000; public String sex; public double getMoney() { return money; } public void setMoney(double money) { this.money = money; } }
package com.test.testfan; public class testfan_01_03_对象 { public static void main(String[] args) { // TODO 自动生成的方法存根 Person p1 = new Person(); Person p2 = new Person(); p1.name = "zhangsan"; p1.setMoney(60000.00); System.out.println(p1.name); System.out.println(p1.getMoney()); System.out.println(p1); System.out.println("-------------"); p2.name = "zhangsan9999"; p2.setMoney(90000.00); System.out.println(p2.name); System.out.println(p2.getMoney()); System.out.println(p2); } }
1.04 继承
package com.test.testfan; public class Person { //成员属性 public String name; public int age; private double money=1000; public String sex; //成员方法 public double getMoney() { return money; } public void setMoney(double money) { this.money = money; } }
package com.test.testfan; public class Student extends Person{ @Override public double getMoney() { // TODO 自动生成的方法存根 //return super.getMoney(); return 9000.00; } }
package com.test.testfan; public class testfan_01_04_继承 { public static void main(String[] args) { // TODO 自动生成的方法存根 Person p1 = new Student(); p1.name = "zhangsan"; p1.setMoney(60000.00); System.out.println(p1.name); System.out.println(p1.getMoney()); System.out.println(p1); } }
1 父类私有成员属性不进行继承
2 继承后方法进行重写 继承类 object类
1.05 Equal_ToString
Ctrl+t 查看类间的继承关系
接口 不进行实现 不可new
抽象类 部分实现 不可new
数组
ArrayList 线性结构 连续空间
LinkLIst 链表结构
集合
package com.test.testfan; public class Person { //成员属性 public String name; public int age; private double money=1000; public String sex; //成员方法 public double getMoney() { return money; } public void setMoney(double money) { this.money = money; } /* (非 Javadoc) * @see java.lang.Object#hashCode() */ @Override public String toString() { return "Person [name=" + name + ", age=" + age + ", money=" + money + ", sex=" + sex + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; long temp; temp = Double.doubleToLongBits(money); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Person other = (Person) obj; if (Double.doubleToLongBits(money) != Double.doubleToLongBits(other.money)) return false; return true; } }
package com.test.testfan; import java.util.ArrayList; import java.util.List; public class testfan_01_04_Equal_ToString { public static void main(String[] args) { // TODO 自动生成的方法存根 Person p1 = new Person(); Person p2 = new Person(); p1.name = "zhangsan"; p1.setMoney(90000.00); System.out.println(p1.name); System.out.println(p1.getMoney()); System.out.println(p1); //tostring 默认输出的是地址 System.out.println("-------------"); p2.name = "zhangsan9999"; p2.setMoney(90000.00); System.out.println(p2.name); System.out.println(p2.getMoney()); System.out.println(p2); System.out.println(p2==p1); //地址比较 System.out.println(p2.equals(p1)); //值比较 List<Person> list9 = new ArrayList<Person>(); List<Object> list10 = new ArrayList<Object>(); } }
1.06 集合1
Collection List ArrayList 数组
LinkedList
Set HashSet 集合 去重
TreeSet
Map HashMap
TreeMap
package com.test.testfan; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.TreeSet; public class testfan_01_05_数组 { public static void main(String[] args) { // TODO 自动生成的方法存根 // 数组 List<String> list = new ArrayList<String>(); //线性 list.add("1"); list.add("1"); list.add("3"); System.out.println(list.size()); List<String> list2 = new LinkedList<String>(); //分块存放 // 集合 去重 Set<String> set = new HashSet<String>(); set.add("1"); set.add("1"); set.add("3"); System.out.println(set.size()); // 集合 排序 Set<String> set2 = new TreeSet<String>(); set2.add("1"); set2.add("1"); set2.add("3"); set2.add("9"); System.out.println(set2.size()); for (String string : set2) { System.out.println(string); } } }
1.07 集合2
package com_01_testfan_02_basic; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.TreeMap; import sun.security.ssl.KerberosClientKeyExchange; public class Day01_05_集合2 { public static void main(String[] args) { // TODO 自动生成的方法存根 /** * HashMap和 TreeMap的比较 * HashMap不进行首字母排序; * TreeMap进行首字母排序 */ //HashMap Map<String, Object> map = new HashMap<String, Object>(); map.put("bname", "zhangsan"); map.put("csex", "男"); map.put("amoney", 10000); Set<String> sets = map.keySet(); System.out.println(sets.getClass()); System.out.println(map.containsKey("33333")); for (String string : sets) { System.out.println("key:" + string + " value:" + map.get(string)); } System.out.println(); //TreeMap Map<String, Object> map2 = new TreeMap<String, Object>(); map2.put("bname", "zhangsan"); map2.put("csex", "男"); map2.put("amoney", 10000); Set<String> sets2 = map2.keySet(); System.out.println(sets2.getClass()); System.out.println(map2.containsKey("33333")); for (String string : sets2) { System.out.println("key:" + string + " value:" + map2.get(string)); } } }