int[] numbers = { 1, 5, 23, 2, 1, 6, 3, 01, 8, 12, 3, 2 };
Arrays.sort(numbers);
for(int i = 1; i < numbers.length; i++) {
if(numbers[i] == numbers[i - 1]) {
System.out.println("Duplicate Cara Pertama : " + numbers[i]);
}
}
Arrays.sort(numbers);
for(int i = 1; i < numbers.length; i++) {
if(numbers[i] == numbers[i - 1]) {
System.out.println("Duplicate Cara Pertama : " + numbers[i]);
}
}
String[] withDuplicates = new String[] {"one","two","three","one"};
String[] withoutDuplicates = new String[] {"one","two","three"};
Set tempSet = new HashSet();
for (String str : withDuplicates) {
if (!tempSet.add(str)) {
System.out.println("Duplicate Cara Kedua : " + str);
}
}
List Add = new ArrayList();
Add.add("Liverpool");
Add.add("Chelsea");
Add.add("Liverpool");
Add.add("Arsenal");
Add.add("Milan");
Add.add("Juventus");
Add.add("Arsenal");
for (String str : Add) {
if (!tempSet.add(str)) {
System.out.println("Duplicate Cara Ketiga : " + str);
}
}
String[] withoutDuplicates = new String[] {"one","two","three"};
Set tempSet = new HashSet();
for (String str : withDuplicates) {
if (!tempSet.add(str)) {
System.out.println("Duplicate Cara Kedua : " + str);
}
}
List
Add.add("Liverpool");
Add.add("Chelsea");
Add.add("Liverpool");
Add.add("Arsenal");
Add.add("Milan");
Add.add("Juventus");
Add.add("Arsenal");
for (String str : Add) {
if (!tempSet.add(str)) {
System.out.println("Duplicate Cara Ketiga : " + str);
}
}
Demikian contoh program dari saya, semoga bermanfaat. GBU.
Related Posts
0 comments:
Posting Komentar