1 ImportJava.util.*;2 classsnow{}3 classPowderextendssnow{}4 classCrustyextendssnow{}5 classSlushextendssnow{}6 7 classLightextendsPowder {}8 classHeavyextendsPowder {}9 Ten One Public classaddinggroups { A - Public Static voidMain (string[] args) { - theCollection<integer> Collection =NewArraylist<integer> (Arrays.aslist ()); -Integer[] Moreints = {4,5,6}; - //Arrays.aslist As the name implies, pass in an array, make out a list. Array conversion to list - Collection.addall (Arrays.aslist (moreints)); + Collections.addall (collection, 7);//variable parameter list - + /*the underlying implementation of Arrays.aslist () is an array, so the dimensions cannot be resized. So the runtime will appear unsupportedoperationexception A List List = Arrays.aslist (n/a); at List.add (4); - System.out.println (list); - */ - System.out.println (collection); - -list<snow> Snow1 = Arrays.aslist (NewPowder (),NewSlush (),NewCrusty ()); in -List<snow> snow2 = Arrays.aslist (NewLight (),NewHeavy ()); to + //Collections.addall (snow2); - theList<snow> SNOW3 =NewArraylist<snow>(); * $Collections.addall (SNOW3,NewLight (),NewHeavy ());Panax Notoginseng - //Explicit type parameter description theList<snow> snow4 = Arrays.<Snow>Aslist (NewLight (),NewHeavy ()); + A the } + -}
Java Collection Review Collection (2) Add a group of elements