摘要: 一:定义以指定格式打印集合的方法(ArrayList类型作为参数),使用门}扩起集合,使用@分隔每个元素。格式参照{元素@元素@元素}。 public static void main(String[] args) { ArrayList<String> list = new ArrayList<> 阅读全文
posted @ 2022-06-29 15:34 魔光领域 阅读(46) 评论(0) 推荐(0) 编辑
摘要: 存储随机数字 1.生成6个1~33之间的随机整数,添加到集合,并遍历集合。 public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<>(); Random ra = new Random(); 阅读全文
posted @ 2022-06-29 15:20 魔光领域 阅读(69) 评论(0) 推荐(0) 编辑
摘要: Arraylist集合概述、基本使用 数组的长度不可以发生改变。 但是Arraylist集合的长度是可以随意变化的。 对于ArrayList来说,有一个尖括号<E>代表泛型。 泛型: 装在集合当中的所有元素,全都是统一的什么类型。 注意: 泛型只能是引用类型,不能是基本类型。 直接打印Arrayli 阅读全文
posted @ 2022-06-29 15:06 魔光领域 阅读(64) 评论(0) 推荐(0) 编辑
摘要: 使用对象类型作为方法的参数 public static void main(String[] args) { Phone p = new Phone(); p.brand = "华为"; p.price = 9999.0; p.color = "黑色"; //传入的是地址值 method(p); } 阅读全文
posted @ 2022-06-29 11:39 魔光领域 阅读(63) 评论(0) 推荐(0) 编辑
摘要: 两个对象使用同一个方法的内存图 public static void main(String[] args) { //根据Phone类创创建一个名为p的对象 //格式:类名称 对象名 = new 类名称(); Phone p = new Phone(); System.out.println(p.b 阅读全文
posted @ 2022-06-29 10:51 魔光领域 阅读(22) 评论(0) 推荐(0) 编辑
摘要: 手机类的练习 Phone类 //成员变量 //品牌 String brand; //价格 double price; //颜色 String color; //成员方法 public void call(String sho){ System.out.println("给"+sho+"打电话"); 阅读全文
posted @ 2022-06-29 10:14 魔光领域 阅读(20) 评论(0) 推荐(0) 编辑