Question Index

What will be the output of the following program?

import java.util.*;
public class SortAlphabets {
    public static void main(String[] args) {
        Alphabets a = new Alphabets();
        Collections.sort(a.alphabets, a);
class Alphabets implements Comparator<Character> {
    List<Character> alphabets = new ArrayList<Character>();
        Alphabets add(Character c) {
        return this;
    public int compare(Character arg0, Character arg1) {
        int result = arg0.compareTo(arg1);
        System.out.print("" + arg0 + arg1 + result + " ");
        return 0;

cz-23 zA57 cA34 zk15 ck-8 zi17 ki2 ci-6 zC55 kC40 iC38 cC32 AC-2
[A, C, c, i, k, z]
cz-23 zA57 Ak-42 ki2 iC38
[c, z, A, k, i, C]
cz-23 cA34 Ak-42 ck-8 zk15 Ai-40 ci-6 ki2 AC-2 cC32
[z, k, i, c, C, A]
Some other output or Compilation Error
Runtime Error



Topic: Java Comparators

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App