One question in the interview requires merging two ArrayList lists and sorting

Source: Internet
Author: User

The problem is very simple, but it is very meaningful, the last time I saw the powerful function of list, I think the question began to the Java API to consider, after all, not all the problems need to brains to think about the algorithm.

For this personal implementation is as follows:

/** merges data and sorts */public class Sortdemo {public static void main (string[] args) {list<object> startlist=new according to small to large Arraylist<object> (); List<object> endlist=new arraylist<object> (); Startlist.add (1); Startlist.add (7); StartList.add (3); Startlist.add (5); Startlist.add (9);//------------------Endlist.add (2); Endlist.add (3); Endlist.add (7); Endlist.add (3); Endlist.add (9); object[] Countlist=compare (startlist, endlist); for (int i=0;i<countlist.length;i++) { System.out.print (Countlist[i]);}} public static object[] Compare (list<object> startlist,list<object> endlist) {startlist.addall (endList); O Bject[] Objects=startlist.toarray (); Arrays.sort (objects); return objects;}
If I put it in the past, I would definitely design a sort of sorting method, such as: bubble sort or choose sort, of course these are familiar ways and easy to write, but I chose the above way in this written test to achieve.

Of course, it can be judged by the execution time for how to compare the relevant programs.

But when writing this code, the individual is still small and fulfilling.

One question in the interview requires merging two ArrayList lists and sorting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.