Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132930 views
License: OTHER
1
import java.util.ArrayList;
2
import java.util.Collections;
3
import java.util.LinkedList;
4
import java.util.List; // nicht java.awt.List!
5
6
public class Main {
7
public static void main(String[] args) {
8
List<Integer> myList = new ArrayList<Integer>();
9
List<Integer> anotherList = new LinkedList<Integer>();
10
11
for (int i = 0; i < 5; i += 1) {
12
myList.add((int) (Math.random() * 100));
13
anotherList.add((int) (Math.random() * 100));
14
}
15
16
System.out.println("myList: " + myList);
17
System.out.println("anotherList: " + anotherList);
18
19
myList.addAll(anotherList);
20
Collections.sort(myList);
21
System.out.println("combined: " + myList);
22
23
for (int myInt : myList) {
24
// do something with myInt...
25
}
26
}
27
}
28
29