zoukankan      html  css  js  c++  java
  • 11.26

    学习了API和String Builder类

    public class StringDemo01 {
    public static void main(String[] args) {
    //public String():创建一个空白字符串对象,不含有任何内容
    String s1 = new String();
    System.out.println("s1:" + s1);

    //public String(char[] chs):根据字符数组的内容,来创建字符串对象
    char[] chs = {'a', 'b', 'c'};
    String s2 = new String(chs);
    System.out.println("s2:" + s2);

    //public String(byte[] bys):根据字节数组的内容,来创建字符串对象
    byte[] bys = {97, 98, 99};
    String s3 = new String(bys);
    System.out.println("s3:" + s3);

    //String s = “abc”; 直接赋值的方式创建字符串对象,内容就是abc
    String s4 = "abc";
    System.out.println("s4:" + s4);
    }
    }

    public class StringBuilderDemo01 {
    public static void main(String[] args) {
    //创建对象
    StringBuilder sb = new StringBuilder();

    //public StringBuilder append(任意类型):添加数据,并返回对象本身
    // StringBuilder sb2 = sb.append("hello");
    //
    // System.out.println("sb:" + sb);
    // System.out.println("sb2:" + sb2);
    // System.out.println(sb == sb2);

    // sb.append("hello");
    // sb.append("world");
    // sb.append("java");
    // sb.append(100);

    //链式编程
    sb.append("hello").append("world").append("java").append(100);

    System.out.println("sb:" + sb);

    //public StringBuilder reverse():返回相反的字符序列
    sb.reverse();
    System.out.println("sb:" + sb);
    }
    }

  • 相关阅读:
    leetcode 18 4Sum
    leetcode 71 Simplify Path
    leetcode 10 Regular Expression Matching
    leetcode 30 Substring with Concatenation of All Words
    leetcode 355 Design Twitte
    leetcode LRU Cache
    leetcode 3Sum
    leetcode Letter Combinations of a Phone Number
    leetcode Remove Nth Node From End of List
    leetcode Valid Parentheses
  • 原文地址:https://www.cnblogs.com/wanghaoning/p/14161646.html
Copyright © 2011-2022 走看看