集合基础
接口
//Implementingthisinterfaceallowsanobjecttobethetargetofthe'for-eachloop'statement.//Iterator其实是一个接口(迭代器)Iterator
迭代器替代了EnumerationIterator允许调用者在迭代期间从底层集合中删除元素,并具有明确定义的语义。
主要方法
boolean hasNext();
E next();
default void remove() {
throw new UnsupportedOperationException('remove');
}
default void forEachRemaining(Consumer super E> action) {
Objects.requireNonNull(action);
while (hasNext())
action.accept(next());
}
Representsanoperationthatacceptsasingleinputargumentandreturnsnoresult.voidaccept(Tt);defaultConsumer
只接受一个参数没有返回值
是集合层次中的根接口jdk中并没有直接实现这个接口,而是由collection派生出特定子接口(例如setlist),这个接口通常用于传递集合并操作他们,具有最大通用性无序的集合如bag或者multisets应该直接实现这个接口对于不直接实现这个接口而是实现其子接口的集合类,构造方法应该满足有一个空的构造方法有一个可以传入集合的构造方法可以有序,可以无序,可以重复,可以不重复
Liststhatsupportthisoperationmayplacelimitationsonwhat*elementsmaybeaddedtothislist.Inparticular,some*listswillrefusetoaddnullelements,andotherswillimpose*restrictionsonthetypeofelementsthatmaybeadde
实现list接口的集合必须有序,是否为空由具体list决定可以通过整形的索引来查找和访问集合中的元素继承了collection接口
/***MarkerinterfaceusedbyListimplementationstoindicatethat*theysupportfast(generallyconstanttimrandomaccess.Theprimary*purposeofthisinterfaceistoallowgenericalgorithmstoaltertheir*behaviortoprovidegoodperformancewhenappliedtoeitherrandomor*sequentialaccesslists./
标记接口,内容为空,只是说明访问时可以采取随机访问
/*Amapcannotcontainduplicatekeys;eachkeycanmaptoatmostonevaluTheMapinterfaceprovidesthreecollectionviews,whichallowamap'scontentstobeviewedasasetofkeys,键collectionofvalues,值orsetofkey-valuemappings.键值对theorderofamapisdefinedastheorderinwhichtheiteratorsonthemap'scollectionviewsreturntheirelements.Allgeneral-purposemapimplementationclassesshouldprovidetwo'standard'constructors:avoid(noarguments)constructorwhichcreatesanemptymap,andaconstructorwithasingleargumentoftypeMap,whichcreatesanewmapwiththesamekey-valuemappingsasitsargument.*/
是否有序由其子类决定,如TreeMap有序,HashMap无序,是针对于值的view而言对于不直接实现这个接口而是实现其子接口的map类,构造方法应该满足有一个空的构造方法有一个可以传入Map的构造方法
类
抽象类
抽象类
提供了Map接口的框架实现对于不可修改的map,继承该类并实现entrySet方法对于可修改的map,除了继承该类,还要额外重写put方法,iterator也要实现remove方法
文章为作者独立观点,不代表观点
CTrump2022-12-25
五大的新能源平台拿项目没问题,但调峰呢?以后绿电要全部进入市场化股票的,这个时间不会太远,因为绿电占比已经上来了,再不解决绿电调峰机制,将严重阻碍绿电的进一步发展。