一.基础概念 为了讲清楚他们的差异,这里先介绍几个概念. 1.1 常量池 所谓常量池:顾名思义就是用来存放一些常量的.该常量是在编译期被确定,并被保存在已编译的.class文件中,其中包括了类,方法,接口等包含的数值常量,字符常量和字符串常量. 1.2 字符串常量池 在常量池中,有个专门用来存储字符串常量的,称之为字符串常量池. 当我们需要使用字符串时,首先会在该字符串常量中查找是否存在该字符串,若存在则直接进行使用:若不存在,则会新建一个对应的字符串,并保存在该字符串常量池中. 1.3 在编译…
一.compareTo(String str)方法 返回值:如果参数字符串等于此字符串,则返回值 0:如果此字符串按字典顺序小于字符串参数,则返回一个小于 0 的值:如果此字符串按字典顺序大于字符串参数,则返回一个大于 0 的值. 1.按字典顺序比较两个字符串 String str0 = "a"; String str1 = "b"; int result0 = str0.compareTo(str1);//-1 System.out.println("r…
1.最大的区别在于String str=null没有分配内存,String str=""分配了内存 2.String str=null   这个引用指向了一个null ,没有地址没有值的地方 3,String str=""   这个引用指向了一个地址,地址里面存的是空的字符…
从string[]转List<string>: " }; List<string> list = new List<string>(str); 从List<string>转string[]: List<string> list = new List<string>(); string[] str = list.ToArray(); Array类实现了数组中元素的冒泡排序.Sort()方法要求数组中的元素实现IComparab…
关于string的定义,请参阅博文http://blog.csdn.net/larry233/article/details/51483827 string的操作 s.empty() //Returns true if s is empty,otherwise returns false s.size() //Returns numbers of characters of s s[n] //Returns the character at position n in s,positions s…
java.string.split() 存在于java.lang包中,返回值是一个数组. 作用是按指定字符或者正则去切割某个字符串,结果以字符串数组形式返回. 例 String [] toSort = // 0 1 2 3 {"aaa:10:1:1", "ccc:30:3:4", "bbb:50:4:5", "ddd:20:5:3", "eee:40:2:20"}; 经过toSort[i].split(&q…
​在此之前有无数次下定决心要把JDK的源码大致看一遍,但是每次还没点开就已被一个超链接或者其他事情吸引直接跳开了.直到最近突然意识到,因为对源码的了解不深导致踩了许多莫名其妙的坑,所以再次下定决心要把常用的类全部看一遍... 一. 声明和成员变量(不可变性) public final class String implements java.io.Serializable, Comparable<String>, CharSequence { private final char value[…
  public class StringDemo01 { public static void main(String[] args) { String s1 = new String("abc"); // a String s2 = "abc"; // b String s3 = new String("abc"); // c System.out.println(s1 == s2); //false System.out.println(s…
转载:https://blog.csdn.net/andychen314/article/details/50857313 答案是 两个对象,要理解这个,就要知道string类的工作原理.下面来慢慢分析一下: public class StringTest { public static void main(String[] args){ String s1="Hello"; String s2="Hello"; String s3=new String("…