Week 13 work set

Problem 1: Create two linear form, are stored { "chen", "wang", "liu", "zhang"} and { "chen", "hu", "zhang"}, find the linear form of these two intersection and union.

Second, the program

package vc;
import java.util.ArrayList;
import java.util.List;
public class ListDemo {
	public static void main(String [] args){
		ArrayList table1 = new  ArrayList();
		table1.add("chen");
        table1.add("wang");
        table1.add("liu");
        table1.add("zhang");
        System.out.println("表1内容" + table1); 
        ArrayList table2 = new ArrayList();
        table2.add("chen");
        table2.add("hu");
        table2.add("zhang");
        System.out.println("表2内容" + table2);
        ArrayList table3 = new ArrayList();
        table3.clear();
        table3.addAll(table1);
        table3.retainAll (Table2); 
        System.out.println ( "the intersection of two linear table is:" + table3); // intersection of 
        table3.clear (); 
        table3.addAll (table1); 
        table3.addAll (Table2) ; 
        System.out.println ( "two sets for the linear form and:" + table3); // set and seeking 
	}     

}

 Third, the operating results

 

Guess you like

Origin www.cnblogs.com/shi13/p/11938674.html