美文网首页
String类中其它的方法

String类中其它的方法

作者: 落在牛背上的鸟 | 来源:发表于2018-03-05 22:55 被阅读68次

其它方法

No 方法名称 类型 描述
1 public String concat(String str) 普通 字符串连接,与"+"类似
2 public String toLowerCase() 普通 大写转小写
3 public String toUpperCase() 普通 小写转大写
4 public String trim() 普通 去掉字符串中左右两边的空格,中间空格保留
5 public int length() 普通 取字符串长度
6 public String intern() 普通 数据入池
7 public boolean isEmpty 普通 判断是否是空字符串(不是null, 而是"",长度0)

范例:代码演示

public class StringOthers {
    public static void main(String[] args) {
        String str_1 = "  hello ";
        String str_2 = "World!  ";
        String str_3 = str_1.concat(str_2);
        String str_4 = "";
        String str_5 = "studenName";
        System.out.println(str_3);

        System.out.println(str_3.toUpperCase());
        System.out.println(str_3.toLowerCase());

        System.out.println("【" + str_3 + "】");
        System.out.println("【" + str_3.trim() + "】");

        System.out.println(str_3.length());

        System.out.println(str_3.isEmpty());
        System.out.println(str_4.isEmpty());

        System.out.println(initCap(str_5));
    }

    public static String initCap(String temp){
        return temp.substring(0,1).toUpperCase() + temp.substring(1);
    }
}

代码结果

  hello World!  
  HELLO WORLD!  
  hello world!  
【  hello World!  】
【hello World!】
16
false
true
StudenName

相关文章

  • String类中其它的方法

    其它方法 范例:代码演示 代码结果

  • Java 最常用的10大算法

    String/Array/Matrix在Java中,String是一个包含char数组和其它字段、方法的类。 逆波...

  • API作业练习答案

    一、简述String类中的equals方法与Object类中的equals方法的不同点。 答:String类中的e...

  • Java 中的 String 类常用方法 Ⅱ

    Java 中的 String 类常用方法 Ⅱ 我们继续来看 String 类常用的方法,如下代码所示: 运行结果:...

  • string类

    string类 1. string类常用方法 2. string类常用方法2 3. string类的查找 判断字符...

  • String 类中的方法

    前言:前面我们学完了类的所有事,包括类的定义使用,抽象类,普通类,接口,以及其中的属性和方法,今天就来一起学习系统...

  • Constructor

    this:继承同一类中的其它构造函数 Class Car{private string _description;...

  • Java常用类笔记

    字符串相关的类 String类及常用方法 String的特性 String类:代表字符串。Java 程序中的所有字...

  • String

    1.String类2.String类和常量池3.String类常用的方法 1.String类 1.String类又...

  • String类概述及其构造方法

    构造方法 String类的判断功能 String类的获取功能 String的转换功能 String类的其他功能

网友评论

      本文标题:String类中其它的方法

      本文链接:https://www.haomeiwen.com/subject/leykfftx.html