03 2022 档案
摘要:public class BufferTest { public static void main(String[] args) throws Exception{// testBufferedReader();// testBufferedWrite("我是你爸爸"); copyFile("C:\
阅读全文
摘要:public class BufferTest { public static void main(String[] args) throws Exception {// testBufferedInputStream();// testBufferedOutputStream(); copyFil
阅读全文
摘要:public static void testFileWriter(String text, String outPath) { try { FileWriter fw = new FileWriter(outPath); //将字符串写到内存中 fw.write(text); //将内存中的数据刷
阅读全文
摘要:public static void copyFile(String inPath, String outPath) { try { FileReader fr = new FileReader(inPath); FileWriter fw = new FileWriter(outPath); ch
阅读全文
摘要:public static void testFileReader(String inPath) { try { //创建字符输入流的对象 FileReader fr = new FileReader(inPath); //创建存放数据的缓冲数组 char[] a = new char[10]; /
阅读全文
摘要:public class T1 { public static void main(String[] args) { //要复制的文件的路径,复制后所到达的文件夹路径+复制后的文件名 copyFile("C:\\Users\\Administrator\\Desktop\\D1-425\\侯超.jp
阅读全文
摘要:public class FileOutputStreamTest { public static void main(String[] args) { testOutputStream(); } public static void testOutputStream(){ try { //指定向2
阅读全文
摘要:public class FileInputStreamTest { public static void main(String[] args) {// testFileInputStream();// testOutPutStream(); } /* 文件字节输入流 FileInputStrea
阅读全文
摘要:public static void main(String[] args) { Dd d = new Dd(); List<String> l1 = new ArrayList<String>(); d.test(l1); List<Integer> l2 = new ArrayList<Inte
阅读全文
摘要:public static void main(String[] args) { B1<Object> b1 = new B1<Object>(); System.out.println(b1.test(1)); B2 b2 = new B2(); System.out.println(b2.tes
阅读全文
摘要:public class 泛型方法 { public static void main(String[] args) { Cc<Object> c = new Cc<Object>(); System.out.println(c.test1("你好"));//String //泛型方法在调用前,没有
阅读全文
摘要:public class 泛型类 { public static void main(String[] args) { A<String> a1 = new A<String>();//在new A的对象指定泛型的类型 类型是String a1.setKey("xxxx");//对象使用setKey
阅读全文
摘要:Student s1 = new Student(14,"张三");Student s2 = new Student(12,"王五");Student s3 = new Student(16,"李四");Student s4 = new Student(11,"lucy");List<Student
阅读全文
摘要:List<String> list = new ArrayList<String>();list.add("b");list.add("a");list.add("123");list.add("a");System.out.println(list);//反转list集合的顺序Collection
阅读全文
摘要://TreeMap的自然排序是字典排序Map<Integer,String> map = new TreeMap<Integer,String>();map.put(4,"a");map.put(3,"a");map.put(2,"a");map.put(1,"a");System.out.prin
阅读全文
摘要:定义一个Map集合Map<String,Integer> map=new HashMap<String,Integer>();//map中key不同,value可以相同map.put("a",1);map.put("b",1);map.put("c",1);System.out.println(ma
阅读全文
摘要:特点:List集合会按照顺序来进行排序 通过ArrayList对象定义一个List集合对象 List<String> list = new ArrayList<String>(); list.add("Hello"); //第一个索引下标0 list.add("Hell");//1 list.add
阅读全文
摘要:定义一个TreeSet对象 Set<Integer> set = new TreeSet<Integer>(); 特点:TreeSet会自动排序,HashSet不会自动排序 用法与HashSet相同,如有不懂请查看上一篇随笔
阅读全文
摘要:HashSet中不允许有重复值,且不按顺序排列 定义一个HashSet: Set set =new HashSet(); HashSet方法如下: //添加元素set.add(1);set.add("acc");System.out.println(set); //移除元素set.remove("a
阅读全文
摘要:public class Person { 匿名代码块第二个输出,一般用来赋初始值 { System.out.println("匿名代码块"); }静态代码块和类一起加载,是第一个输出,只执行一次 static { System.out.println("静态代码块"); } 第三个输出 publi
阅读全文
摘要:类型之间的转换 :父类 子类高 低Person student = new Student();student将这个对象转换为Student类型,就可以使用student类型的方法了((Student) student).go();子类转换为父类 可能丢失自己的本来的一些方法!student本来是P
阅读全文
摘要:左边是对象,右边是类,当对象是右边类或子类所创建的对象时,返回true,反之则为false Object object = new Student();System.out.println(object instanceof Student);System.out.println(object in
阅读全文
摘要:多态注意事项1.多态是方法的多态,属性没有多态2.父类和子类,有联系 类型转换异常 ClassCastException3.多态存在的条件:继承关系 方法需要重写 父类的引用指向的是子类对象 Father f1 = new son();不能重写的方法:1.static 方法属于类,不属于实例2.fi
阅读全文
摘要:super注意点: 1.super调用父类的构造方法,必须在构造方法的第一个 2.super必须只能出现在子类的方法或者构造方法中 3.super和this不能同时调用构造方法Vs this: 代表的对象不同: this:本身调用者这个对象 super:代表父类对象的引用 前提 this:没有继承也
阅读全文
摘要:比如在子类中定义这样一个方法 public void test1(){ print();//student this.print();//student super.print();//person} public void print() { System.out.println("STUDENT
阅读全文
摘要:静态方法和非静态方法:测试类中的代码A a = new A();a.test();B b = new B();b.test();A类中的代码(静态方法)A类继承B类 public static void test() { System.out.println("A-TEST");} B类中的代码(静
阅读全文
摘要:构造器:1.和类名相同2.没有返回值作用:1.new 本质在调用构造方法2.初始化对象的值注意点:1.定义了有参构造之后,如果想使用无参构造,显示的定义一个无参的构造
阅读全文