Javaコンセプトまとめ(十二)

3188 ワード

Javaコンセプトまとめ(十三)
1:Scannerの使用(了解)(1)JDK 5以降に現れるキーボード入力用のクラス.(2)構造方法:A:System.inこれ.これは標準的な入力ストリームであり、キーボード入力Bの構造方法InputStreamis=Systemに対応する.in;
        Scanner(InputStream is)
    C:     
        Scanner sc = new Scanner(System.in);
(3)      :
    A:hasNextXxx()           
    B:nextXxx()          
(4)        
    A:public int nextInt()
    B:public String nextLine()
(5)        
    A:   Scanner  ,     ,              。
    B:    :
        a:      Scanner  
        b:             ,          

2:Stringクラスの概要と使用(把握)(1)複数文字からなる一連のデータ.文字配列と相互変換できます.(2)構築方法:A:public String()B:public String(byte[]bytes)C:public String(byte[]bytes,int offset,int length)D:public String(char[]value)E:public String(char[]value,int offset,int count)F:public String(String original)の下にあるのは構築方法ではないが、結果として文字列オブジェクトG:String s="hello";(3)文字列の特徴A:文字列が付与されると変更できない.注意:ここでは、文字列の内容は変更できません.参照ではなく変更できません.B:字面値は文字列オブジェクトとして、構造方法によってオブジェクトを作成する異なるString s=new String(「hello」)である.String s=「hello」との違いは?(4)文字列の面接問題(プログラムを見て結果を書く)A:==とequals()String s 1=new String("hello");String s2 = new String("hello"); System.out.println(s1 == s2);//false System.out.println(s1.equals(s2));//true
        String s3 = new String("hello");
        String s4 = "hello";
        System.out.println(s3 == s4);// false
        System.out.println(s3.equals(s4));// true

        String s5 = "hello";
        String s6 = "hello";
        System.out.println(s5 == s6);// true
        System.out.println(s5.equals(s6));// true
    B:      
        String s1 = "hello";
        String s2 = "world";
        String s3 = "helloworld";
        System.out.println(s3 == s1 + s2);// false
        System.out.println(s3.equals((s1 + s2)));// true

        System.out.println(s3 == "hello" + "world");// false       ,   true
        System.out.println(s3.equals("hello" + "world"));// true
(5)      (          )
    A:    
        boolean equals(Object obj)
        boolean equalsIgnoreCase(String str)
        boolean contains(String str)
        boolean startsWith(String str)
        boolean endsWith(String str)
        boolean isEmpty()
    B:    
        int length()
        char charAt(int index)
        int indexOf(int ch)
        int indexOf(String str)
        int indexOf(int ch,int fromIndex)
        int indexOf(String str,int fromIndex)
        String substring(int start)
        String substring(int start,int end)
    C:    
        byte[] getBytes()
        char[] toCharArray()
        static String valueOf(char[] chs)
        static String valueOf(int i)
        String toLowerCase()
        String toUpperCase()
        String concat(String str)
    D:    
        a:     
            String replace(char old,char new)
            String replace(String old,String new)
        b:     
            String trim()
        c:       
            int compareTo(String str)
            int compareToIgnoreCase(String str) 
(6)      
    A:      
    B:     
    C:        ,          
    D:            ,    
    E: int               
    F:     
    G: