public?static?void??main(String[]?args)?{
成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比民豐網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式民豐網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋民豐地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴。
Integer[]?A?=?{1,2,3,4};
Integer[]?B?=?{1,3,7,9,11};
ListInteger?listA?=?Arrays.asList(A);
ListInteger?listB?=?Arrays.asList(B);
ListInteger?jiaoji?=?new?ArrayListInteger();
for(Integer?a:listA){
if(listB.contains(a)){
jiaoji.add(a);
}
}
System.out.println(jiaoji);
ListInteger?bingji?=?new?ArrayListInteger();
for(Integer?a:listA){
if(!bingji.contains(a)){
bingji.add(a);
}
}
for(Integer?b:listB){
if(!bingji.contains(b)){
bingji.add(b);
}
}
System.out.println(bingji);
ListInteger?chaji?=?new?ArrayListInteger();
for(Integer?a:listA){
if(!listB.contains(a)){
chaji.add(a);
}
}
System.out.println(chaji);
}
public class PlayCard {
private ListInteger list;
/**
* JAVA編程創(chuàng)建一個(gè)List集合cards,再54張撲克牌存放到其中
* (1)用3種不同方法輸出54張牌;
* (2)調(diào)用Collections方法隨機(jī)分派54張牌
*/
public PlayCard() {
list = new ArrayListInteger();
for(int i=1;i55;i++){
list.add(i);
}
}
public void showPlayCard(){
System.out.println("方式一");
for(Integer i : list){
System.out.print(i+"\t");
}
System.out.println("方式二");
for(int i=0;ilist.size();i++){
System.out.print(list.get(i)+"\t");
}
System.out.println("方式三");
Iterator Integer it = list.iterator();
while(it.hasNext()){
System.out.print(it.next()+"\t");
}
}
// TODO調(diào)用Collections方法隨機(jī)分派54張牌
public void randomPlayCards(){
// 把牌打亂
Collections.shuffle(list);
}
public static void main(String[] args) {
PlayCard p = new PlayCard();
p.randomPlayCards();
p.showPlayCard();
}
}
public static void main(String[] args) {
SetCharacter result = new HashSetCharacter();
SetCharacter set1 = new HashSetCharacter() {
{
add('a');
add('b');
add('c');
add('d');
add('e');
}
};
SetCharacter set2 = new HashSetCharacter() {
{
add('a');
add('b');
add('c');
}
};
result.clear();
result.addAll(set1);
result.retainAll(set2);
System.out.println("交集:" + result);
result.clear();
result.addAll(set1);
result.removeAll(set2);
System.out.println("差集:" + result);
result.clear();
result.addAll(set1);
result.addAll(set2);
System.out.println("并集:" + result);
result.clear();
result.addAll(set1);
if(result.containsAll(set2)){
result.removeAll(set2);
System.out.println("補(bǔ)集:"+result);
}else{
System.out.println("無補(bǔ)集");
}
}
分享標(biāo)題:集合java編程代碼,java集合源碼
當(dāng)前地址:http://vcdvsql.cn/article32/heoosc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、品牌網(wǎng)站建設(shè)、做網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)、電子商務(wù)、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)