首页 > 其他分享 >字符串

字符串

时间:2023-02-17 11:47:26浏览次数:44  
标签:lang Ljava java String StringBuilder 字符串 INVOKEVIRTUAL

final字符串连接

  /*!!!!!!final字符串连接+*/
    @Test
    public void fianlStringTest() {
        final String str2 = "a";
        final String str3 = "b";
        String str4 = str2 + str3;
        String str5 = "ab";
        System.out.println("1: " + (str4 == str5));//true

        final String str8 = "d";
        String str9 = "c" + str8 + "e";
        String str89 = "cde";
        System.out.println("2: " + (str9 == str89)); //true

        final String strA = "f";
        String strB = "g";
        String strS = strA + strB;
        String strPool = "fg";
        System.out.println("3:" + (strPool == strS)); //false
    }

final字符串连接-字节码

// access flags 0x1
public fianlStringTest()V
@Lorg/junit/Test;()
L0
LINENUMBER 55 L0
LDC "a"
ASTORE 1
L1
LINENUMBER 56 L1
LDC "b"
ASTORE 2
L2
LINENUMBER 57 L2
LDC "ab"
ASTORE 3
L3
LINENUMBER 58 L3
LDC "ab"
ASTORE 4
L4
LINENUMBER 59 L4
GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
NEW java/lang/StringBuilder
DUP
INVOKESPECIAL java/lang/StringBuilder. ()V
LDC "1: "
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
ALOAD 3
ALOAD 4
IF_ACMPNE L5
ICONST_1
GOTO L6
L5
FRAME FULL [string/IfEqualsTest java/lang/String java/lang/String java/lang/String java/lang/String] [java/io/PrintStream java/lang/StringBuilder]
ICONST_0
L6
FRAME FULL [string/IfEqualsTest java/lang/String java/lang/String java/lang/String java/lang/String] [java/io/PrintStream java/lang/StringBuilder I]
INVOKEVIRTUAL java/lang/StringBuilder.append (Z)Ljava/lang/StringBuilder;
INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String;
INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
L7
LINENUMBER 61 L7
LDC "d"
ASTORE 5
L8
LINENUMBER 62 L8
LDC "cde"
ASTORE 6
L9
LINENUMBER 63 L9
LDC "cde"
ASTORE 7
L10
LINENUMBER 64 L10
GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
NEW java/lang/StringBuilder
DUP
INVOKESPECIAL java/lang/StringBuilder. ()V
LDC "2: "
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
ALOAD 6
ALOAD 7
IF_ACMPNE L11
ICONST_1
GOTO L12
L11
FRAME FULL [string/IfEqualsTest java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String] [java/io/PrintStream java/lang/StringBuilder]
ICONST_0
L12
FRAME FULL [string/IfEqualsTest java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String] [java/io/PrintStream java/lang/StringBuilder I]
INVOKEVIRTUAL java/lang/StringBuilder.append (Z)Ljava/lang/StringBuilder;
INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String;
INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
L13
LINENUMBER 66 L13
LDC "f"
ASTORE 8
L14
LINENUMBER 67 L14
LDC "g"
ASTORE 9
L15
LINENUMBER 68 L15
NEW java/lang/StringBuilder
DUP
INVOKESPECIAL java/lang/StringBuilder. ()V
LDC "f"
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
ALOAD 9
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String;
ASTORE 10
L16
LINENUMBER 69 L16
LDC "fg"
ASTORE 11
L17
LINENUMBER 70 L17
GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
NEW java/lang/StringBuilder
DUP
INVOKESPECIAL java/lang/StringBuilder. ()V
LDC "3\uff1a"
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
ALOAD 11
ALOAD 10
IF_ACMPNE L18
ICONST_1
GOTO L19
L18
FRAME FULL [string/IfEqualsTest java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String] [java/io/PrintStream java/lang/StringBuilder]
ICONST_0
L19
FRAME FULL [string/IfEqualsTest java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String java/lang/String] [java/io/PrintStream java/lang/StringBuilder I]
INVOKEVIRTUAL java/lang/StringBuilder.append (Z)Ljava/lang/StringBuilder;
INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String;
INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
L20
LINENUMBER 71 L20
RETURN
L21
LOCALVARIABLE this Lstring/IfEqualsTest; L0 L21 0
LOCALVARIABLE str2 Ljava/lang/String; L1 L21 1
LOCALVARIABLE str3 Ljava/lang/String; L2 L21 2
LOCALVARIABLE str4 Ljava/lang/String; L3 L21 3
LOCALVARIABLE str5 Ljava/lang/String; L4 L21 4
LOCALVARIABLE str8 Ljava/lang/String; L8 L21 5
LOCALVARIABLE str9 Ljava/lang/String; L9 L21 6
LOCALVARIABLE str89 Ljava/lang/String; L10 L21 7
LOCALVARIABLE strA Ljava/lang/String; L14 L21 8
LOCALVARIABLE strB Ljava/lang/String; L15 L21 9
LOCALVARIABLE strS Ljava/lang/String; L16 L21 10
LOCALVARIABLE strPool Ljava/lang/String; L17 L21 11
MAXSTACK = 4
MAXLOCALS = 12

String toLowerCase()

 @Test
    public void toLowerCaseTest() {
        String s1 = "Hello";
        String s2 = "hello";
        String s3 = s1.toLowerCase();//new String("hello")
        String s4 = s2.toLowerCase();//没有改变返回this 所以s3=s4
        System.out.println(s1 == s3);//false
        System.out.println(s1 == s4);//false
        System.out.println(s2 == s3);//false
        System.out.println(s2 == s4);//true
        System.out.println(s2.equals(s3));//true 比较的是内容
    }

标签:lang,Ljava,java,String,StringBuilder,字符串,INVOKEVIRTUAL
From: https://www.cnblogs.com/haveanicedayfh/p/17129537.html

相关文章

  • 字符串的排列
    字符串的排列给你两个字符串 s1 和 s2,写一个函数来判断s2是否包含s1 的排列。如果是,返回true;否则,返回false。换句话说,s1的排列之一是s2的子串。示例......
  • C# 字符串数组去重(去除数组中重复元素)
    1、去重distinct()或者GroupBy(p=>p).Select(p=>p.Key),去重的对象都需要为数组,具体看代码stringitemfileids="1,3,3,5,4,6,8,4,7,5,1,2";string[]sArray=itemf......
  • 《判断字符串是IP还是域名》
    首先假设输入字符串为域名,然后检查输入字符串是否是一个合法的IPv4地址。如果不是,则将输入字符串解析为域名,并输出结果。如果是一个合法的IPv4地址,则直接输出结果。注......
  • java字符串之间的拼接方法
    在java开发中,有很多时候,需要把一个集合或者数组中的数据进行拼接,拼接成一个全新格式的字符串,这时候就用到了java中的一些方法,方法如下:一、Joiner-guava点击查看代码/......
  • Windows命令findstr文本文件中查找字符串(findstr-对应于Linux中的grep命令)
    一、实例如查找coco.names文件中的car所在的行:findstr/N/A:02carcoco.names或将全部内容(用点.代替)转出到文本文件:findstr/N/A:02.coco.names>coco.txt二、知识点......
  • acwing 我在哪?(字符串哈希)
    原题链接题解分析设答案为ans,那么大于ans,肯定不成立,小于ans成立,这符合二分答案的特点然后使用unordered_set和substr进行查重substr:第一个参数为开始项,第二个参数......
  • 字符串类型
    字符串操作vars,s1,s2:String;begins:='microsoftisabigCompany';s2:=Trimleft(s);//s2的内容为'microsoftisabigCompany's2:=TrimRig......
  • 字符串方法
    >>>spam='Helloworld'>>>spam.upper()#所有字母被转为大写'HELLOWORLD'>>>spam.lower()#所有字母被转为小写'helloworld'>>>spam#未改变原字符串'......
  • APS.NET Core 6.0Json任何类型读取到字符串属性The JSON value could not be converte
    在升级.netsdk到6.0版本后出现TheJSONvaluecouldnotbeconvertedtoSystem.String.原因是我代码定义的类型是string,但是传参的时候写了int,publicoverridevoidC......
  • 判断字符串是否与变量相符
    判断字符串是否与变量相符利用Equals()来判断字符串是否与变量一致usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassMa......