编程语言
首页 > 编程语言> > java知识点:IO

java知识点:IO

作者:互联网

IO四大基类

BIO、NIO、AIO


反射

实现方式:


String

public static void main(String[] args) throws Exception {
        String s = "hello";
        String s1 = s;
        String s2 = s;
        //通过使用替换函数修改字符
        String s3 = s1.replace('e', 'o');
        System.out.println(s);//hello
        System.out.println(s1);//hello
        System.out.println(s2);//hello
        System.out.println(s3);//hollo

        //通过反射修改字符
        Field value = String.class.getDeclaredField("value");
        value.setAccessible(true);
        char[] chs =(char[]) value.get(s2);
        chs[0] = 'o';

        System.out.println(s); //hollo
        System.out.println(s1);//hollo
        System.out.println(s2);//hollo
        System.out.println(s3);//hollo
    }

辨析 String s1 = "hello"String s2 = new String("hello")

public static void main(String[] args) {
        String s = "hello";
        String s1 ="hello";
        String s2 = new String("hello");
        String s3 = new String("hello");
        String s4 = new String("hello").intern();

        System.out.println(s==s1); //true
        System.out.println(s==s2);//false
        System.out.println(s==s4);//true
        System.out.println(s2==s3);//false
        System.out.println(s2==s4);//false
    }

String、StringBuffer、StringBuilder

Integer、int数值相等

public static void main(String[] args) {
	Integer a1 = 1;
	Integer a2 = 1;
	Integer a3 = new Integer(1);
	Integer a4 = new Integer(1);
	int a5= 1;
	System.out.println(a1==a2);//true
	System.out.println(a3==a1);//false
	System.out.println(a5==a1);//true
	System.out.println(a5==a3);//true
	System.out.println(a2==a3);//false

	//常量池中的Integer对象值在-128到127之间
	Integer b1 = 128;
	Integer b2 = 128;
	System.out.println(b1==b2);//false
}

包装类和基本数据类型比较


集合

Iterator 和 ListIterator 有什么区别?

标签:知识点,java,String,System,IO,println,Integer,hello,out
来源: https://www.cnblogs.com/sleepyheadLK/p/16684422.html