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