1)String Utility:String提供了几种内置的实用程序方法。诸如indexOf(),lastIndexOf(),startsWith(),startsWith(),isEmpty(),equals(),equalsIgnoreCase()之类的方法就是字符串实用程序的一部分。
在下面的代码片段中,String类的concat()方法将两个String对象的内容合并为一个。但是,“ str ”所指的原始值保持不变。concat()方法将创建一个新的字符串对象。就像concat()方法一样,其他String方法(例如toUpperCase(),toLowerCase()和trim()方法)都会返回新的String对象。
jshell> String str = "Nhooo"; str ==> "Nhooo" jshell> str.concat(" is e-learning app"); $3 ==> "Nhooo is e-learning app" jshell> str str ==> "Nhooo" ^ jshell> String str1 = str.concat(".") str1 ==> "Nhooo." jshell> str1 str1 ==> "Nhooo." jshell> String str = str.concat(" is e-learning app"); str ==> "Nhooo is e-learning app" jshell> str str ==> "Nhooo is e-learning app" jshell> String str1 = "Nhooo"; str1 ==> "Nhooo" jshell> str1.concat(" is e-learning app"); $2 ==> "Nhooo is e-learning app" jshell> str1 str1 ==> "Nhooo" jshell> String str2 = str1.concat(" is e-learning app"); str2 ==> "Nhooo is e-learning app" jshell> str1 str1 ==> "Nhooo" jshell> String str3 = str2.concat("."); str3 ==> "Nhooo is e-learning app." jshell> str1 str1 ==> "Nhooo" jshell> str2 str2 ==> "Nhooo is e-learning app" jshell> String s = "Nhooo is e-learning app." s ==> "Nhooo is e-learning app." jshell> s.toUpperCase() $10 ==> "nhooo IS E-LEARNING APP." jshell> s.toLowerCase() $11 ==> "nhooo is e-learning app."