字串的哈希定 」数据结构中的Hash查找 J String类已内置了生成Hash码的方法 阅读示例 StringHash Code java并思索如何应用 HaSh码来加快信息检索的速度。 dEmonstrating String Method hashCode The hash code for hello"is 99162322 The hash code for"Hello"is 69609650 2021/2/24 北京理工大学计算机系
2021/2/24 北京理工大学计算机系 11 字串的哈希定位 ◼ 数据结构中的Hash查找 ◼ String类已内置了生成Hash码的方法. ◼ 阅读示例StringHashCode.java并思索如何应用 Hash码来加快信息检索的速度
字串查找 Method indexof Method lastIndexof B c is located at index 2 a'is located at index 13 自学示例: s' is located at index-1 Last 'c is located at index 15 StringIndexMethods.java Last ' a'is located at index 13 Last'$ is located at index-1 def is located at index 3 denis located at index 16 hello"is located at index.1 Last"def is located at index 16 Last"def is located at index 16 Last"hello"is located at index-1 2021/2/24 北京理工大学计算机系
2021/2/24 北京理工大学计算机系 12 字串查找 ◼ Method indexOf ◼ Method lastIndexOf ◼ 自学示例: StringIndexMethods.java
提取子串与字串连接 subString方法 Demonstrating String Class Subst Substring from index 20 to end is"hijkIm" 示例: Substring java Substring from index O up to 6 is"abcdef 确定 concat方法 示例: StringConcat java Demonstrating String lethod concat +运算符 s1= Hap py 52= Birthday Result of s1 concat( s2 )= Happy Birthday s1 after concatenation Happy 确定 2021/2/24 北京理工大学计算机系
2021/2/24 北京理工大学计算机系 13 提取子串与字串连接 ◼ subString方法 示例:SubString.java ◼ concat方法 示例:StringConcat.java ◼ +运算符
String类的其他方法 Replace Demonstrating liscellaneou.. X toUpperCase S2= GOOD BYE toLower Case Replace 'I with L' in $1: heLLo Trim s1. toUppercaseo= HELLO J tostring s2. toLowercaseo= good bye s3 after trim ="spaces u to CharArray 自学示例: s1 as a character aray hello 确定 StringMisc2, java 2021/2/24 北京理工大学计算机系
2021/2/24 北京理工大学计算机系 14 String类的其他方法 ◼ Replace ◼ toUpperCase toLowerCase ◼ Trim ◼ toString ◼ toCharArray ◼ 自学示例: StringMisc2.java
将其它类型的数据转为字串 使用 valueof,注意,这是 个静态方法 Demonstrating String Class.. X 示例: char array abcdef part of char array= def Stringvalueof java boolean= true char= Z int= 7 long=10000000 at=25 double= 33.333 Object = hello 确定 2021/2/24 北京理工大学计算机系
2021/2/24 北京理工大学计算机系 15 将其它类型的数据转为字串 ◼ 使用ValueOf,注意,这是 一个静态方法 ◼ 示例: StringValueOf.java