zoukankan      html  css  js  c++  java
  • SummerVocation_Learning--java的String 类

     java中String属于java.lang的package包,是一个类。代表不可变的字符序列。

        String类的常见构造方法:

                String(String original),创建一个对象为original的拷贝。

                String(char[] value),用一个字符数组创建一个String对象。

                String(char[] value,int offset,int count),用一个数组从offset项开始的count个字符序列创建一个String对象。

        举例1:

     1 public class TestString {
     2 
     3     public static void main(String[] args) {
     4         // TODO Auto-generated method stub
     5         String s1 = "hello",s2 = "world";
     6         String s3 = "hello";
     7         System.out.println(s1==s3); //判断s1,s3是否相等。输出true。
     8         
     9         s1 = new String("hello");
    10         s2 = new String("hello");
    11         System.out.println(s1==s2); //false
    12         System.out.println(s1.equals(s2)); //true
    13         
    14         char[] c= {'h','e','l','l','o',',','w','o','r','l','d'};
    15         String s4 = new String(c);
    16         String s5 = new String(c, 6, 5);
    17         System.out.println(s4); //hello,world
    18         System.out.println(s5); //world
    19     }
    20 
    21 }
  • 相关阅读:
    C#第十六节课
    Hadoop系列(三):hadoop基本测试
    Hadoop系列(二):Hadoop单节点部署
    Hadoop系列(一):Hadoop集群搭建
    Stars project
    Tornado实现多进程/多线程的HTTP服务
    python paramiko模块
    爬虫代理
    tornado之用户验证装饰器
    tornado自定义session
  • 原文地址:https://www.cnblogs.com/DSYR/p/9292646.html
Copyright © 2011-2022 走看看