zoukankan      html  css  js  c++  java
  • String 基本使用方法, 以及要注意的事项

    package chengbaoDemo;
    
    public class Test01 {
        public static void main(String[] args) {
         //字符串的两种创建形式 String s1
    = "sed";  //一个对象 String s2 = new String("sed");  //两个对象 System.out.println(s1.equals(s2)); //true 比价对象的内容是否相等 System.out.println(s1 == s2); //false 比较对象的引用是否相等 String s3 = "qwerty"; //System.out.println(s3.indexOf('s')); 数组越界 String s4 = s3.substring(3); System.out.println(s4); String s5 = s3.replace('q', 's'); System.out.println(s5); s3.split("e"); //此处不可以使用单引号 //查找字符串的序号 System.out.println(s3); //查找字符的序号,第一次出现的位置 System.out.println(s3.indexOf('w')); //查找字符的序号,最后一次出现的位置、 System.out.println(s3.lastIndexOf('e')); //下面三种比较方式可以用来比较两个字符串是否相等(不区分大小写) //(1)比较两个字符串(不区分大小写) System.out.println("ASd".equalsIgnoreCase("asd")); //true //(2)将字符串转为大写 System.out.println("Asd".toUpperCase()); //ASD //(3)将字符串转为小写 System.out.println("aWSD".toLowerCase()); //awsd //去除字符串两端的空格 System.out.println(" de desdew ".trim()); // de desdew /** * 注意区分两种声明字符串对象的数目 * 在下面循环叠加字符串对象是, 每次循环,都创建一个行的对象 * 10次循环后,共有11个字符串对象(第二种创建字符串对象, 有12个对象) * 这种方法是是不可取的, 十分浪费空间 */ String gh = "a"; //一个对象 // String gh = new String("a"); //两个对象 for (int i = 0; i < 10; i++) { gh += i; } System.out.println(gh); //a0123456789 } }
  • 相关阅读:
    GRIDVIEW鼠标移动行变色
    如何在网页中实现打字效果
    C#的6种常用集合类
    开发和使用Web用户控件
    C# DataGridView的常用用法
    SQL精妙语句
    Web 调试代理软件-Fiddler
    RegisterStartupScript和RegisterClientScriptBlock的用法
    简单地过一下五个控件(ScriptManager、ScriptManagerProxy、UpdatePanel、 UpdateProgress和Timer
    Android4.0 SDK功能详解
  • 原文地址:https://www.cnblogs.com/chengbao/p/5182878.html
Copyright © 2011-2022 走看看