1.4.1 简单的jAPI介绍
在线API地址:Overview (Java SE 9 & JDK 9 )
常用API String / ArrayList。
1.4.2 创建对象内容所在地区,方法,属性,地址
方法区>栈地址>堆地址>常量词
简单判断,提示双引号中的内容相互作用任在常量池,一方不为双引号则存入堆内存内存中
查看反编译的代码
第一步:拷贝路径
第二步:打开文件夹,输入路径,回退一个文档找到javasepro文件夹;
第三步:按命名找到运行的class文件,将其拖入程序编译,可获得计算机省略优化的代码
1.4.4 String类的常用API
== 比较两个元素的地址
string.equals(Object anObject) //比较字符串内容
string equalsIgnoreCase(String AnotherString) // 忽略大小写比较内容
String 的常用API方法
案例:登录账户后输入手机号(进行隐藏)
static Random r=new Random();
public static void main(String[] args) {
String admin="admin";
String passuser="passuser";
Scanner sc=new Scanner(System.in);
for (int i = 3; i > 0; i--) {
String code = Code();
System.out.println("请输入您的账号");
String adminInput=sc.next();
System.out.println("请输入您的密码");
String passuserInput=sc.next();
System.out.println("当前验证码为:"+code);
System.out.println("请输入验证码");
String CodeInput=sc.next();
if(admin.equals(adminInput)&&passuser.equals(passuserInput)&&code.equalsIgnoreCase(CodeInput)){
System.out.println("登录成功");
System.out.println("请输入您的手机号码");
String tel=sc.next();
String Begin=tel.substring(0,3);
String End=tel.substring(7);
System.out.println(Begin+"****"+End);
break;
}else{
System.out.println("用户名、密码、验证码输入错误");
if(i>1){
System.out.println("当前输入机会还剩"+(i-1)+"次");
}else{
System.out.println("账号已被锁定");
}
}
}
}
public static String Code(){
String code="";
for (int i = 0; i < 5; i++) {
int num=r.nextInt(2);
if (num==0){
code+=(char)(r.nextInt(10) + 48);
}else if(num==1){
code+=(char)(r.nextInt(25) + 65);
}else{
code+=(char)(r.nextInt(25) + 97);
}
}
return code;
}
1.4.5 ArrayList类的常用API
ArrayList list =new ArrayList(); // 创建一个不限制大小的list数组
arr.add(E e) //指定的元素e追加到此集合末尾
arr.add(int index,E element) //在此集合中的指定位置插入指定元素e
ArrayList<字符串类型> //表示只能存储该种字符串类型 String / Integer