Group Exercises:
List<list<student>> list=new arraylist<list<student>> (); This is a two-dimensional set that can be grouped to create a list in the first loop, The object to be returned when the loop is received, and then add the list to the two-dimensional collection
Package Com.hanqi;import Java.util.arraylist;import Java.util.list;import Java.util.random;public class Fenzu {public static void Main (string[] args) {list<student> l=datasourcemodel.getstulist (); List<list<student>> list=new arraylist<list<student>> ();/*int[][] I=new int[5][];int[ ] A=new int[]{1,2,3};i[3]=a; System.out.println (i[3][1]); * * random r=new random (); int fenzur=4; int zsize=13; for (int i=0;i< (13/fenzur); i++) { list<student> li= new arraylist<student> (); for (int j=0;j<fenzur;j++) { int a=r.nextint (4); Li.add (L.get (a)); L.remove (a); if (L.size () <2) { li.add (l.get (0)); } } List.add (LI); System.out.println (LI); System.out.println (Li.size ());}}}
Deleting duplicate objects can also use a double for loop to find duplicates, or you can convert the list collection to a set set, because set cannot be duplicated, so it is automatically deleted repeatedly.
public static void Chachong (List l) {for (int a=0;a<l.size (); a++) {int size=0;for (int b=0;b<l.size (); b++) {if (l.get (a). Equals (L.get (b))) {size++;if (size>1) {l.remove (b);}}}} public static void Kaitou (List l) {//j begins with the name for (int i=0;i<l.size (); i++) {if (' J ' = = (L.get (i). toString (). CharAt (0))) {/ /Judgment two characters typeface etc. can be used ==system.out.println (L.get (i));}}} public static void Bnianling (List l) {//is more than age for (int a=0;a<l.size (); a++) {if (((Student) L.get (a)). Getage () >25) {// The student of parentheses is strongly turned into student type?? System.out.println (L.get (a));}}}
Because the map does not have a direct iterator interface, you can move the keyset method to get the key value, assign the key value to the set set (because the list can be repeated, and set can not be duplicated) or collection set, you can implement the iterator interface.
Collection<integer> c=m.keyset ();iterator<integer> i=c.iterator (); while (I.hasnext ()) { int a=i.next (); if (a>=1004&&a<=1009) { System.out.println (a); if (a==1005) { i.remove (); Continue;} }
Java Collection exercises