当前位置: 首页 > news >正文

忆唐网不做网站做品牌网站怎么上传模板

忆唐网不做网站做品牌,网站怎么上传模板,网站制作网络推广关键词排名,长兴县住房和城乡建设局 网站概念#xff1a; ArrayList是一种有序可变的容器#xff0c;ArrayList构造会自动创建长度为10的容器#xff0c;超过10会自动增加 集合和数组的区别 : ​ 共同点#xff1a;都是存储数据的容器 ​ 不同点#xff1a;数组的容量是固定的#xff0c;集合的容量是可变的 集合…概念 ArrayList是一种有序可变的容器ArrayList构造会自动创建长度为10的容器超过10会自动增加 集合和数组的区别 : ​ 共同点都是存储数据的容器 ​ 不同点数组的容量是固定的集合的容量是可变的 集合底层也是数组数组的效率会更好但是功能有限如果要存储的数据经常发生变化就使用集合 ArrayList的构造方法和成员方法 public ArrayList()创建一个空的集合对象public boolean add(E e)将指定的元素追加到此集合的末尾public void add(int index,E element)在此集合中的指定位置插入指定的元素public boolean remove(Object o)删除指定的元素返回删除是否成功public E remove(int index)删除指定索引处的元素返回被删除的元素public E set(int index,E element)修改指定索引处的元素返回被修改的元素public E get(int index)返回指定索引处的元素public int size()返回集合中的元素的个数public static void main(String[] args) {//创建集合ArrayListString array new ArrayListString();//public boolean add(E e) 将指定的元素追加到此集合的末尾array.add(hello);array.add(hello);array.add(world);array.add(java);System.out.println(第一次添加 array);// public void add(int index,E element) 在此集合中的指定位置插入指定的元素array.add(1, 我来个插队);System.out.println(array);// public boolean remove(Object o) 删除指定的元素返回删除是否成功boolean r array.remove(hello);System.out.println(是否删除成功 r);System.out.println(删除后 array);// public E remove(int index) 删除指定索引处的元素返回被删除的元素array.remove(2);System.out.println(删除后 array);// public E set(int index,E element) 修改指定索引处的元素返回被修改的元素array.set(1,helloPlus);System.out.println(修改后 array);// public E get(int index) 返回指定索引处的元素System.out.println(array.get(1));// public int size() 返回集合中的元素的个数System.out.println(array.size());}键盘录入学生信息到集合 public static void main(String[] args) {//创建集合对象ArrayListStudent array new ArrayListStudent();//为了提高代码的复用性我们用方法来改进程序addStudent(array);//遍历集合采用通用遍历格式实现for (int i 0; i array.size(); i) {Student s array.get(i);System.out.println(s.getName() , s.getAge());}}public static void addStudent(ArrayListStudent array) {//键盘录入学生对象所需要的数据Scanner sc new Scanner(System.in);System.out.println(请输入学生姓名:);String name sc.nextLine();System.out.println(请输入学生年龄:);int age sc.nextInt();//创建学生对象把键盘录入的数据赋值给学生对象的成员变量Student student new Student(name, age);//往集合中添加学生对象array.add(s);}删除注意 public static void main(String[] args) {// 创建集合ArrayListString list new ArrayList();list.add(abc);list.add(123);list.add(123);list.add(45126);list.add(654);for (int i 0; i list.size(); i) {String s list.get(i);// 尽量用常量调equals不要用变量if (123.equals(s)) {list.remove(i);/**不做--的话就会有遗漏实现的原理是删除第一个指定元素以后往后面判断的时候所有的元素的素索引都会往前移动当指针走到索引1这时候索引1是第一个123把它删掉了然后从索引2整体向前移动现在的索引1是第二个123这时候指针又开始了。就刚好错过了第二个123。如果加上--在删除以后就会回退一个索引然后循环又就不会错过了*/i--;}}System.out.println(list);} 集合筛选 public static void main(String[] args) {ArrayListStudent list new ArrayList();Student stu1 new Student(韩信, 2);Student stu2 new Student(李白, 23);Student stu3 new Student(露娜, 24);list.add(stu1);list.add(stu2);list.add(stu3);ArrayListStudent newList getList(list);for (int i 0; i newList.size(); i) {Student student newList.get(i);System.out.println(student.getName() : student.getAge());}}private static ArrayListStudent getList(ArrayListStudent list) {// 创建新集合ArrayListStudent newlist new ArrayList();// 遍历集合,获取每一个学生对象for (int i 0; i list.size(); i) {Student stu list.get(i);// 调用getage判断年龄是否小于18int age stu.getAge();if (age 18) {// 把年龄小于18的学生存到新集合newlist.add(stu);}}return newlist;}
http://www.zqtcl.cn/news/800395/

相关文章:

  • 网站建设注意细节问题微信二维码
  • 凡科做的网站提示证书错误网络营销渠道可分为哪几种
  • 南京手机网站制作公司免费设计房屋效果图软件有哪些
  • 定制类网站怎么样做网页设计
  • 企业门户网站建设优势网站登录模版
  • 六盘水建设网站徐州建站平台
  • 昆明有多少做网站的公司公司软文代写
  • 东莞模板网站做一个电子商务网站在哪里做
  • 给别人网站做跳转株洲专业网站排名优化
  • 国外网站空间租用费用网站前端设计图
  • 宜州做网站点点网 xml转wordpress
  • 太原建站方法erp系统好上手吗
  • 网站建设如何实现检索功能河南城乡建设网站
  • 江苏做电缆桥架的公司网站购物网站答辩ppt怎么做
  • 惠州网站建设系统公司公司网站建设公司
  • 做酒类直供网站行吗石家庄桥西网站制作公司
  • 电子商务门户网站的研究与实现漳州做网站多少钱
  • 咖啡网站源码呼和浩特网站建设价位
  • 邯郸哪儿能做网站广州冼村房价多少钱
  • 网站建设开发成本设计素材库
  • wordpress获取站点链接wordpress 滑动验证
  • 怎么把网站上的通栏手机公司网站建设
  • 微山县建设局官方网站wordpress 内容换行
  • 网站选择空间ps个人主页设计
  • 河北网站seo外包网站嵌入百度地图
  • 公司怎么开网站WordPress有哪些工具
  • 一流专业建设网站原平新闻头条最新消息
  • 网站开发文档模板 开源北京保障房建设项目网站
  • 营销型网站分类网站关键词如何快速上首页
  • 帝国和WordPress比较wordpress文章页标题优化