String&集合
1. 包
- 我们的类都是放在某个"包(文件夹)"下,定义包:
package xxx.yyy; - 如果某个类需要使用其他包下的类,要“导包”访问:
import xxxx.yyy.mmm; - 在使用Java类库的类时,也需要打包,除了java.lang包不需要导
import java.util.Scanner;
2.String类
2.1 String的构造方法
public class Demo03 {
public static void main(String[] args) {
String s1 = new String();
String s2 = new String("Hello");
char[] chars = {'a', 'b', 'c', '你', '好'};
String s3 = new String(chars);
System.out.println(s3);
byte[] bytes = {97, 98, 99, 100};
String s4 = new String(bytes);
System.out.println(s4);
}
}
2.2 String的常用方法
![请添加图片描述](https://img-blog.csdnimg.cn/3987901258b04756b9f1ad9d28cf2004.png)
2.3 String的注意事项
public class Demo12 {
public static void main(String[] args) {
String s1 = "Hello";
String s2 = "Hello";
System.out.println(s1 == s2);
String s5 = new String("Hello");
String s6 = new String("Hello");
System.out.println(s5);
System.out.println(s1 == s5);
System.out.println(s5 == s6);
System.out.println(s1.equals(s5));
}
}
3.ArrayList集合
3.1常用方法
![请添加图片描述](https://img-blog.csdnimg.cn/464adc2f6b8b4210936956d4242d1647.png)