To merged Charts

To merged Charts,第1张

To merged Charts
import java.util.ArrayList;
import java.util.linkedList;

public class TestTwo {
    //To merged Charts:
    //The code is as follows:
    public static void main(String[] args) {
        //ArrayList:
        ArrayList Fir=new ArrayList<>();
        Fir.add(5);
        Fir.add(2);
        Fir.add(0);
        ArrayList Sec=new ArrayList<>();
        Sec.add(6);
        Sec.add(0);
        Sec.add(2);
        Sec.add(5);
        ArrayList merge =new ArrayList<>();
        merge.addAll(Fir);
        merge.addAll(Sec);
        System.out.println("Fir:"+Fir);
        System.out.println("Sec:"+Sec);
        System.out.println("merge:"+merge);
        //linkedList:
        linkedList Thi=new linkedList<>();
        Thi.add(6);
        Thi.add(6);
        Thi.add(6);
        linkedList Fiv=new linkedList<>();
        Fiv.add(8);
        Fiv.add(8);
        Fiv.add(8);
        linkedList merged=new linkedList<>();
        merged.addAll(Thi);
        merged.addAll(Fiv);
        System.out.println("Thi:"+Thi);
        System.out.println("Fiv:"+Fiv);
        System.out.println("merged:"+merged);
    //Using Iterators for ArraysList:
        //对于ArrayList使用迭代器:
        ArrayList Six =new ArrayList<>();
        Six.add(6);
        Six.add(6);
        Six.add(9);
        Six.add(9);
        ArrayList Sev=new ArrayList<>();
        Sev.add(8);
        Sev.add(8);
        Sev.add(6);
        Sev.add(6);
        ArrayList mergeThree=new ArrayList<>();
        Iterator i =Six.iterator();//遍历Six表,然后把Six表中的所有元素一个一个的传输进Sev表里面,达到合并两个图表的效果
        while (i.hasNext()){
            Sev.add((int)i.next());
        }
        System.out.println("mergeThree:"+Sev);
        //Using Iterators for linkedList:
        //对于linkedList使用迭代器:
        linkedList Eig=new linkedList<>();
        Eig.add(6);
        Eig.add(0);
        Eig.add(2);
        Eig.add(5);
        linkedList Nin=new linkedList<>();
        Nin.add(9);
        Nin.add(6);
        Nin.add(9);
        Nin.add(8);
        linkedList mergedFour=new linkedList<>();
        Iterator first =Eig.iterator();//对于linkedList使用迭代器也是遍历Eig图表,然后把Eig图表中的所有元素一个一个的添加到Nin图表中,达到合并列表的目的
        while (first.hasNext()){
            Nin.add((int)first.next());
        }
        System.out.println("mergedFour:"+Nin);
        //Merge multiply lists using for loop(使用for循环合并多个列表)。
        //For loop is also useful to merged two lists(使用for循环对于合并两个列表也是很有用的).
        ArrayList digitOne=new ArrayList<>();
        digitOne.add(6);
        digitOne.add(0);
        digitOne.add(8);
        digitOne.add(9);
        ArrayList digitTwo =new ArrayList<>();
        digitTwo.add(5);
        digitTwo.add(0);
        digitTwo.add(2);
        digitTwo.add(4);
        ArrayList mergeFive=new ArrayList<>();//The for loop traverses both the ArrayLists and adds all the elements one by one to a newly created list(该for循环遍历这两个ArrayList列表,并将列表中的所有元素一个一个的添加到新创建的列表中。)
        for (int k=0;k 
The results are as follows:
Show results:
Fir:[5, 2, 0]
Sec:[6, 0, 2, 5]
merge:[5, 2, 0, 6, 0, 2, 5]
Thi:[6, 6, 6]
Fiv:[8, 8, 8]
merged:[6, 6, 6, 8, 8, 8]
mergeThree:[8, 8, 6, 6, 6, 6, 9, 9]
mergedFour:[9, 6, 9, 8, 6, 0, 2, 5]
mergeFive:[6, 0, 8, 9, 5, 0, 2, 4]
digitOne[6, 0, 8, 9, 5, 0, 2, 4]
Listone:
2	4	6	
Listtwo:
8	10	12	
merged list:
2	4	6	8	10	12	

Process finished with exit code 0

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5715513.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存