zoukankan      html  css  js  c++  java
  • 04-课后作业2-动手动脑及String类整理

    1. 动手动脑之String.equals()方法

     
    public class StringEquals {
        
    /**
         * @param args the command line arguments
         */
        
    	public static void main(String[] args) {
            
    		String s1=new String("Hello");
            
    		String s2=new String("Hello");
            
    		System.out.println(s1==s2);
            
    		System.out.println(s1.equals(s2));
            
    		String s3="Hello";
            
    		String s4="Hello";
              
    		System.out.println(s3==s4);
            
    		System.out.println(s3.equals(s4)); 
        
    	}
    
    }
    

      程序结果截图:

    2.String类的Length()、charAt()、 getChars()、replace()、 toUpperCase()、 toLowerCase()、trim()、toCharArray()使用说明

    Length():

    返回调用此方法的字符串的长度(int)

    charAt() :

    方法用于返回指定索引处的字符,索引范围为从 0 到 length() - 1。

    返回指定索引处的字符

    getChars():

    void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin):

    将字符从此字符串复制到目标字符数组。

    参数:

    srcBegin -- 字符串中要复制的第一个字符的索引。

    srcEnd -- 字符串中要复制的最后一个字符之后的索引。

    dst -- 目标数组。

    dstBegin -- 目标数组中的起始偏移量。

    replace():

    String replace(char oldChar, char newChar)

    replace() 方法通过用 newChar 字符替换字符串中出现的所有 oldChar 字符,并返回替换后的新字符串。

    public String replace(char oldChar, char newChar)   用字符newChar替换当前字符串中所有的oldChar字符,并返回一个新的字符串。

    参数:

         oldChar -- 原字符。

         newChar -- 新字符。

      返回值:替换后生成的新字符串。

     toUpperCase()   toLowerCase()

    字符串中字符的大小写转换
    1)public String toLowerCase()//返回将当前字符串中所有字符转换成小写后的新串
    2)public String toUpperCase()//返回将当前字符串中所有字符转换成大写后的新串

    trim():

     String trim():

     trim() 方法用于删除字符串的头尾空白符,截去字符串两端的空格,但对于中间的空格不处理。

     参数:无

    返回值:删除头尾空白符的字符串。

    toCharArray():

    char[] toCharArray():

    toCharArray() 方法将字符串转换为字符数组。

      参数:无

      返回值:字符数组

  • 相关阅读:
    hibernate 中createQuery与createSQLQuery(转载)

    cookie记住密码
    An Introduction to Shiro (formerly JSecurity) – A Beginner’s Tutorial Part 5
    An Introduction to Shiro (formerly JSecurity) – A Beginner’s Tutorial Part 2
    An Introduction to Shiro (formerly JSecurity) – A Beginner’s Tutorial Part 1
    VS2010 常用功能代码段
    ffmpeg vc2010 lib修复
    多功能视频播放组件演示Demo
    ACE 功能函数笔记
  • 原文地址:https://www.cnblogs.com/cj-125/p/7744270.html
Copyright © 2011-2022 走看看