工具类

代码块
```package com.foreknow.utils;
/**
 * java常用的工具类(API文档)
 * Object中的方法:hashCode()区别对象的唯一性 返回整形
 *                          String  toString()
 *                                   返回该对象的字符串
 * String类中的方法:helloworld 
 *                    String concat(String str)将指定字符串连接到该字符串的结尾               
 *                    int length()返回字符串的长度。     
 *                    String trim()返回字符串的副本,忽略前导空白和尾部空白  
 *                    String[] split(String regex)拆分字符串。
 *                   boolean equals(Object anObject) 将字符串与指定对象比较  
 *                   面试题:==与equals()的区别?
 *                               
 * @author Administrator
 *
 */
public class Test {
    
    public static void main(String[] args) {
        System.out.println("-------------==与equals的区别---------");
        int a=1;
        int b=1;
        String s1="abc";
        String s2="abc";
        String s3=new String("abc");
        String s4=new String("def");
        System.out.println(a==b);//true
        System.out.println(s1==s2);//true
        System.out.println(s1.equals(s2));//true
        System.out.println(s3==s4);//false  除了比较值外,还要比较内存地址
        System.out.println(s3.equals(s4));//true  因为String中的equals方法重写了Object中的equals方法,所以只需要比较值
         System.out.println(s1==s3);//false
         System.out.println(s1.equals(s3));//true

        
        
        
        System.out.println("-------------==与equals的区别---------");
        System.out.println("abc".equals("abc"));
        System.out.println("-----------");
        String name="aa bb cc dd";
        String[] array=name.split(" ");
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
        System.out.println("---------------------------");
        
        
        Test test=new Test();
        Test test1=new Test();
        System.out.println(test.hashCode());
        System.out.println(test1.toString());
        
        String s="hello";
        //String ss=s.concat("world");
        System.out.println(s.concat("world").concat("abc"));
        System.out.println("字符串的长度为:"+s.length());
        
        System.out.println("helloworld".substring(1, 9));
        System.out.println("helloworld".substring(2));
        System.out.println("hello".toUpperCase());
        System.out.println("WORLD".toLowerCase());
        
        String query="         java3    ";
        System.out.println(query);
        System.out.println(query.trim());
    }

}

你可能感兴趣的:(工具类)