What is the result?

Given:

1. import java.util.*;
2.
3. public class LetterASort {
4. public static void main(String[] args) {
5. ArrayList<String> strings = new ArrayList<String>();
6. strings.add(“aAaA”);
7. strings.add(“AaA”);
8. strings.add(“aAa”);
9. strings.add(“AAaa”);
10. Collections.sort(strings);
11. for (String s : strings) {
12. System.out.print(s + ” “);
13. }
14. }
15. }

What is the result?

Given:

1. import java.util.*;
2.
3. public class LetterASort {
4. public static void main(String[] args) {
5. ArrayList<String> strings = new ArrayList<String>();
6. strings.add(“aAaA”);
7. strings.add(“AaA”);
8. strings.add(“aAa”);
9. strings.add(“AAaa”);
10. Collections.sort(strings);
11. for (String s : strings) {
12. System.out.print(s + ” “);
13. }
14. }
15. }

What is the result?

A.
Compilation fails.

B.
aAaA aAa AAaa AaA

C.
AAaa AaA aAa aAaA

D.
AaA AAaa aAaA aAa

E.
aAa AaA aAaA AAaa

F.
An exception is thrown at runtime.



Leave a Reply 1

Your email address will not be published. Required fields are marked *