### 对两个整数的ArrayLists进行排序

• list x = 4 6 9 9
• list y = 4 5 8 11

``````public static void main(String[] args) {
ArrayList<Integer> a = new ArrayList<Integer>();

ArrayList<Integer> b = new ArrayList<Integer>();

ArrayList<Integer> c = new ArrayList<Integer>();

int smallest = c.get(0);

for (int i = 0; i < c.size(); i++) {

if (c.get(i) < smallest) {

smallest = c.get(i);
}
}
``````

#### 2 个答案:

``````Collections.sort(arrayList);
``````

``````int smallest = c.get(0);

for (int i = 0; i < c.size(); i++) {

if (c.get(i) < smallest) {

smallest = c.get(i);
}
}
``````

``````for (int i = 0; i < c.size(); i++) {

if (c.get(i) < smallest) {

smallest = c.get(i);
}
}
``````

``````        System.out.println("Before sorting-->" +c );
for (int i = 0; i < c.size()-1; i++) {
for(int j=i+1; j <c.size();j++)
{
if(c.get(i) > c.get(j))
{
int temp = c.get(j);
c.set(j, c.get(i));
c.set(i, temp);
}
}
}
System.out.println("After sorting-->" +c );
``````

``````Before sorting-->[1, 4, 9, 16, 4, 7, 9, 9, 11]
After sorting-->[1, 4, 4, 7, 9, 9, 9, 11, 16]
``````

OR

``````    List<Integer> xList = Arrays.asList(4,6,9,9);
List<Integer> yList = Arrays.asList(4,5,8,11);
List<Integer> result = new ArrayList<Integer>();

System.out.println("Before sorting-->" +result );

Collections.sort(result);
System.out.println("After sorting-->" +result );
``````

``````Before sorting-->[4, 6, 9, 9, 4, 5, 8, 11]
After sorting-->[4, 4, 5, 6, 8, 9, 9, 11]
``````