两个案例熟悉String的基本操作

编程入门 行业动态 更新时间:2024-10-07 04:33:45

两个案例<a href=https://www.elefans.com/category/jswz/34/1767330.html style=熟悉String的基本操作"/>

两个案例熟悉String的基本操作

1、第一个案例

  • Java语言规范要求完全相同的字符串字面量,应该包含同样的Unicode字符序列(包含同一份码点序列的常量),并且必须是指向同一个String类实例。
package string;
public class StringTest4 {public static void main(String[] args) {System.out.println();System.out.println("1");System.out.println("2");System.out.println("3");System.out.println("4");System.out.println("5");System.out.println("6");System.out.println("7");System.out.println("8");System.out.println("9");System.out.println("10");
//      如下 的字符串 “1” 到 “10” 不会再次被加载System.out.println("1");System.out.println("2");System.out.println("3");System.out.println("4");System.out.println("5");System.out.println("6");System.out.println("7");System.out.println("8");System.out.println("9");System.out.println("10");}
}D:\Java\jdk-17\bin\java.exe -agentlib:jdwp=transport=dt_shmem,address=javadebug,suspend=y,server=n -javaagent:C:\Users\dgq\AppData\Local\JetBrains\IntelliJIdea2023.2\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "F:\IdeaProjects\JavaSenior\out\production\jdk8;D:\develop\maven\repository\junit\junit\4.13.1\junit-4.13.1.jar;D:\develop\maven\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\BaiduNetdiskDownload\IntelliJ IDEA 2023.2\lib\idea_rt.jar" string.StringTest4
Connected to the target VM, address: 'javadebug', transport: 'shared memory'1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
Disconnected from the target VM, address: 'javadebug', transport: 'shared memory'Process finished with exit code 0

2、第二个案例

package string;public class Memory {public static void main(String[] args) {int i = 1;Object obj = new Object();Memory mem = new Memory();mem.foo(obj);}private void foo(Object param) {String str = param.toString();System.out.println(str);}}
D:\Java\jdk-17\bin\java.exe "-javaagent:D:\BaiduNetdiskDownload\IntelliJ IDEA 2023.2\lib\idea_rt.jar=35590:D:\BaiduNetdiskDownload\IntelliJ IDEA 2023.2\bin" -Dfile.encoding=UTF-8 -classpath F:\IdeaProjects\JavaSenior\out\production\jdk8;D:\develop\maven\repository\junit\junit\4.13.1\junit-4.13.1.jar;D:\develop\maven\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar string.Memory
java.lang.Object@404b9385Process finished with exit code 0

 

更多推荐

两个案例熟悉String的基本操作

本文发布于:2024-02-13 14:33:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759357.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:熟悉   案例   两个   操作   String

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!