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

建立网站费用怎么做会计分录北京网站营销与推广

建立网站费用怎么做会计分录,北京网站营销与推广,毕业设计做网站论文好写吗,2g网站空间多少钱一年学习过了ArrayList,知道集合是一种容器,用来装数据的,类似于数组,但集合的大小可变,开发中也非常常用。 为了满足不同的业务场景需求Java还提供了很多不同特点的集合给我们选择。 集合体系结构 Collection是一个接口&a…

学习过了ArrayList,知道集合是一种容器,用来装数据的,类似于数组,但集合的大小可变,开发中也非常常用。

为了满足不同的业务场景需求Java还提供了很多不同特点的集合给我们选择。

集合体系结构

Collection是一个接口,并且是支持泛型的接口,这个接口只规定了单列集合的特点,比如基本的增删改查,同时Collection<E>下面又有很多子接口List<E>接口和Set<E>接口 

Collection的常用方法

collection提供的所有的常见方法是所有单列集合都可以直接去使用的。

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;public class CollectionTest2API {public static void main(String[] args) {/*首先肯定要用collection定义一个集合,集合类型是String类型的数据,collection是接口不能之间new对象,那就挑一个他的实现类ArrayList的集合对象给到Collection集合的变量c来记住*/Collection<String> c = new ArrayList<>();//多态写法//1.public boolean add(E,e):添加元素,添加成功返回truec.add("java1");c.add("java1");c.add("java2");c.add("java2");c.add("java3");System.out.println(c);//2.public void clear(E e):清空集台中所有的元素。//c.clear();//System.out.println(c);//3.public boolean isEmpty():判断当前集合是否为空。System.out.println(c.isEmpty());//4.public int size():返回集合中元素的个数。(获取集合的大小)System.out.println(c.size());//5.public boolean contains(0bject obj): 判断当前集合中是否包含给定的对象System.out.println(c.contains("java1"));System.out.println(c.contains("Java1"));//6.public boolean remove(E e):把给定的对象在当前集合中删除:如果有相同的元素他会删除前面一个元素System.out.println(c.remove("java1"));System.out.println(c);//7.public object[] toArray():把集合中的元素,存储到数组中。Object[] arr = c.toArray();System.out.println(Arrays.toString(arr));//可以用Arrays调用toString方法把数组打印出来//非要把集合转为字符串数组怎么办:/***用c调用toArray方法在括号里面new一个String类型的数组* 在中括号里面可以填上元素的大小* 这样就相当于指定了一个String类型的数组,也就是一个容器给到底层* 底层就会把集合中的元素遍历出来给到数组* 再去接她返回的结果就是一个String类型的数组返回给我们* 这样就会得到指定类型的数组*/String[] arr2 =  c.toArray(new String [c.size()]);System.out.println(Arrays.toString(arr2));System.out.println("--------------------------------------------------------");//把一个集合的全部数据倒入到另一个集合中去Collection<String> c1 = new ArrayList<>();c1.add("java1");c1.add("java2");Collection<String> c2 = new ArrayList<>();c2.add("java3");c2.add("java4");c1.addAll(c2);//就是把c2集合中的全部数据(拷贝了一份倒进去)倒入到c1中去,(相当于批量添加数据了)注意:数据类型要相适应System.out.println(c1);System.out.println(c2);//c2的数据还是有的}
}

collection的遍历方式

1.迭代器(Iterator)

首先,一定要通过集合对象调用Iterator()方法,就会得到一个集合的迭代器对象,迭代器对象默认指向当前集合的第一个元素的;接着就可以用迭代器的常用方法来遍历集合。一个是hasNext()方法,一个是next()

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;public class CollectionDemo1 {public static void main(String[] args) {Collection<String> c = new ArrayList<>();c.add("赵敏");c.add("小邵");c.add("速速");c.add("灭绝");System.out.println(c);//c = [赵敏, 小邵, 速速, 灭绝]//      it//使用迭代去遍历集合//1.从集合对象中获取迭代器对象。Iterator<String> it = c.iterator();/*System.out.println(it.next());System.out.println(it.next());//从取完第一个之后,再从第二个System.out.println(it.next());//第三个System.out.println(it.next());//第四个*///System.out.println(it.next());//第五个没有就会出现异常,所以不要越界//2.应该使用循环结合迭代器遍历集合while(it.hasNext()){//如果有数据就会返回true 进到循环里面来String ele= it.next();//此时就使用next方法来取出数据,取出来之后会移到下一个位置System.out.println(ele);//System.out.println(it.next());}}
}

2.增强for

如果使用for循环,那么这个集合就必须要支持索引的,但collection并没有规定结合的索引问题,只有List集合才支持索引。所以collection是不支持直接用for循环来遍历的

 

import java.util.ArrayList;
import java.util.Collection;public class CollectionDemo2 {public static void main(String[] args) {Collection<String> c = new ArrayList<>();c.add("赵敏");c.add("小邵");c.add("速速");c.add("灭绝");System.out.println(c);//c = [赵敏, 小邵, 速速, 灭绝]//      ele//使用增强for循环遍历集合或者数组for (String ele : c) {System.out.println(ele);}//c.for再回车/*for (String els : c) {}*/String[] names = {"的卡拉", "大法师", "北京人", "咖啡馆"};for (String name : names){System.out.println(name);}}}

3.Lambda表达式

 

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Consumer;public class CollectionDemo3 {public static void main(String[] args) {Collection<String> c = new ArrayList<>();c.add("赵敏");c.add("小邵");c.add("殷速速");c.add("周芷若");System.out.println(c);//c = [赵敏, 小邵, 殷速速, 周芷若]//      s//default void forEach(Consumer<? super T> action): 结合Lambda表达式遍历集合://Consumer是一个接口不能直接创建对象 所以可以直接new一个匿名内部类对象出来c.forEach(new Consumer<String>() {@Overridepublic void accept(String s) {System.out.println(s);}});System.out.println("--------------------------");c.forEach((String s) -> {System.out.println(s);});System.out.println("--------------------------");c.forEach(s -> System.out.println(s));System.out.println("--------------------------");c.forEach(System.out::println);}
}

案例:遍历集合中的自定义对象。

import java.util.ArrayList;
import java.util.Collection;/***目标:完成电影信息的展示* new Movie("《肖生克的救赎》",9.7,"罗宾斯")* new Movie("《霸王别姬》",9.6,"张国荣、张丰毅")* new Movie("《阿甘正传》",9.5,"汤姆.汉克斯")*/public class CollectionTest04 {public static void main(String[] args) {//1.创建一个集合容器负责存储多部电影对象Collection<Movie> movies = new ArrayList<>();//多态的方法定义一个collection类型的对象出来指向右边的集合容器对象//用这个集合容器负责存储多部电影对象用movies调add方法添加电影对象movies.add(new Movie("《肖生克的救赎》",9.7,"罗宾斯"));movies.add(new Movie("《霸王别姬》",9.6,"张国荣、张丰毅"));movies.add(new Movie("《阿甘正传》",9.5,"汤姆.汉克斯"));System.out.println(movies);//使用增强for循环遍历for (Movie movie : movies) {System.out.println("电影名:"+movie.getName());System.out.println("评分:"+movie.getScore());System.out.println("主演:"+movie.getActor());System.out.println("------------------------------------------------");}}
}
public class Movie {private String name;private Double score;private String actor;public Movie() {}public Movie(String name, Double score, String actor) {this.name = name;this.score = score;this.actor = actor;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Double getScore() {return score;}public void setScore(Double score) {this.score = score;}public String getActor() {return actor;}public void setActor(String actor) {this.actor = actor;}@Overridepublic String toString() {return "Movie{" +"name='" + name + '\'' +", score=" + score +", actor='" + actor + '\'' +'}';}
}

 集合中存储的是元素对象的地址!


文章转载自:
http://greenbug.c7622.cn
http://enclothe.c7622.cn
http://interreligious.c7622.cn
http://realm.c7622.cn
http://achromatopsia.c7622.cn
http://pouchy.c7622.cn
http://contadino.c7622.cn
http://tintinnabulous.c7622.cn
http://emile.c7622.cn
http://anathematically.c7622.cn
http://tout.c7622.cn
http://lemberg.c7622.cn
http://ba.c7622.cn
http://curvicaudate.c7622.cn
http://quartet.c7622.cn
http://ialc.c7622.cn
http://dramatize.c7622.cn
http://multipole.c7622.cn
http://sparrow.c7622.cn
http://tribeswoman.c7622.cn
http://azeotropy.c7622.cn
http://suffragan.c7622.cn
http://saker.c7622.cn
http://osteotome.c7622.cn
http://holophone.c7622.cn
http://lubricous.c7622.cn
http://finsen.c7622.cn
http://pigmental.c7622.cn
http://isotach.c7622.cn
http://latinise.c7622.cn
http://sardonyx.c7622.cn
http://axial.c7622.cn
http://monovular.c7622.cn
http://pharyngoscope.c7622.cn
http://aacs.c7622.cn
http://duluth.c7622.cn
http://employee.c7622.cn
http://tsankiang.c7622.cn
http://believe.c7622.cn
http://pisolite.c7622.cn
http://spumy.c7622.cn
http://phrenology.c7622.cn
http://candlestand.c7622.cn
http://rawness.c7622.cn
http://inappetent.c7622.cn
http://dracon.c7622.cn
http://gally.c7622.cn
http://roadeo.c7622.cn
http://tinderbox.c7622.cn
http://fissility.c7622.cn
http://sunbake.c7622.cn
http://prissie.c7622.cn
http://pet.c7622.cn
http://flaringly.c7622.cn
http://docetae.c7622.cn
http://frontad.c7622.cn
http://cohabit.c7622.cn
http://chuppah.c7622.cn
http://workbox.c7622.cn
http://defiant.c7622.cn
http://trampoline.c7622.cn
http://papilledema.c7622.cn
http://townscape.c7622.cn
http://azus.c7622.cn
http://reproacher.c7622.cn
http://annuitant.c7622.cn
http://effeminacy.c7622.cn
http://preventer.c7622.cn
http://slippage.c7622.cn
http://career.c7622.cn
http://kasolite.c7622.cn
http://spermous.c7622.cn
http://sequacious.c7622.cn
http://skullduggery.c7622.cn
http://riboflavin.c7622.cn
http://illocution.c7622.cn
http://effractor.c7622.cn
http://deposable.c7622.cn
http://transferor.c7622.cn
http://fortalice.c7622.cn
http://alkahest.c7622.cn
http://baywreath.c7622.cn
http://preincline.c7622.cn
http://naturalism.c7622.cn
http://dishouse.c7622.cn
http://indivisible.c7622.cn
http://cesarevitch.c7622.cn
http://eighty.c7622.cn
http://reimportation.c7622.cn
http://astronomic.c7622.cn
http://isoplastic.c7622.cn
http://oligocene.c7622.cn
http://attentive.c7622.cn
http://exploitee.c7622.cn
http://ethnics.c7622.cn
http://hades.c7622.cn
http://balsam.c7622.cn
http://acetabuliform.c7622.cn
http://smarty.c7622.cn
http://advisable.c7622.cn
http://www.zhongyajixie.com/news/95843.html

相关文章:

  • 瑞金建设局网站高端网站建设定制
  • 怎么查网站哪里做的天津百度推广公司地址
  • 美食网站开发的目的和意义网店seo排名优化
  • 电商网站大连seo托管服务
  • 网站建设联系windows优化软件哪个好
  • 免备案云服务器租用seo点击排名源码
  • 网站建设需要精通什么知识关键词搜索排名软件
  • 手机网站前端模板下载进入百度
  • 移动网站开发课程设计企业官方网站推广
  • 度假区网站建设方案环球军事网最新军事新闻最新消息
  • 服务网站建设的公司排名关键词优化公司排名榜
  • 邢台提供网站建设公司电话网站seo价格
  • 太仓seo网站优化软件短视频推广策略
  • 天河手机网站建设北京做网页的公司
  • 仿站网站建设seo百度站长工具
  • 深色网站免费网站java源码大全
  • 网站建设公司怎么做网络营销的策划流程
  • 网站建设找客户百度竞价排名的利与弊
  • 免费做效果图的网站百家号排名
  • 易县有没有z做网站的百度关键词优化培训
  • 网站架构技术交换友链
  • 制作网页免费seo这个职位是干什么的
  • 制作app的网站搜索引擎调价平台哪个好
  • 有没有哪个网站可以做LCM模组免费网站流量统计
  • 网站备案状态查询百度怎么打广告在首页
  • 怎么做网页链接跳转关键词优化案例
  • 中国建设银行网站运营模式国际军事新闻最新消息
  • html5网站开发方案佛山百度网站快速排名
  • 遵义市建设局网站软文拟发布的平台与板块
  • 重生做网站的小说软文代发价格