❌ A. LinkedHashMap: {B=5, A=2, C=1, E=3, D=4}; TreeMap: {B=5, D=4, E=3, A=2, C=1} ❌ B. LinkedHashMap: {B=5, A=2, C=1, D=4, E=3}; TreeMap: {B=5, A=2, C=1, D=4, E=3} ❌ C. LinkedHashMap: {A=2, B=5, C=1, D=4, E=3}; TreeMap: {C=1, A=2, E=3, D=4, B=5} ✅ D. LinkedHashMap: {A=2, B=5, C=1, D=4, E=3}; TreeMap: {B=5, D=4, E=3, A=2, C=1} ❌ E. Error ❌ F. None of the above
Explanation: 1. LinkedHashMap Behavior: • LinkedHashMap maintains the insertion order of elements. • Here, linkedHashMap will display entries in the exact order they were inserted: {A=2, B=5, C=1, D=4, E=3}.
2. TreeMap with Custom Comparator: • TreeMap typically orders entries based on the natural order of keys, but here it uses a custom comparator to sort entries in descending order based on values from linkedHashMap. • Comparator.comparingInt(linkedHashMap::get).reversed() sorts treeMap by values in descending order, resulting in {B=5, D=4, E=3, A=2, C=1}.
3. Expected Output: • The LinkedHashMap output maintains the insertion order. • The TreeMap output shows entries sorted by values in descending order based on linkedHashMap values.
❌ A. LinkedHashMap: {B=5, A=2, C=1, E=3, D=4}; TreeMap: {B=5, D=4, E=3, A=2, C=1} ❌ B. LinkedHashMap: {B=5, A=2, C=1, D=4, E=3}; TreeMap: {B=5, A=2, C=1, D=4, E=3} ❌ C. LinkedHashMap: {A=2, B=5, C=1, D=4, E=3}; TreeMap: {C=1, A=2, E=3, D=4, B=5} ✅ D. LinkedHashMap: {A=2, B=5, C=1, D=4, E=3}; TreeMap: {B=5, D=4, E=3, A=2, C=1} ❌ E. Error ❌ F. None of the above
Explanation: 1. LinkedHashMap Behavior: • LinkedHashMap maintains the insertion order of elements. • Here, linkedHashMap will display entries in the exact order they were inserted: {A=2, B=5, C=1, D=4, E=3}.
2. TreeMap with Custom Comparator: • TreeMap typically orders entries based on the natural order of keys, but here it uses a custom comparator to sort entries in descending order based on values from linkedHashMap. • Comparator.comparingInt(linkedHashMap::get).reversed() sorts treeMap by values in descending order, resulting in {B=5, D=4, E=3, A=2, C=1}.
3. Expected Output: • The LinkedHashMap output maintains the insertion order. • The TreeMap output shows entries sorted by values in descending order based on linkedHashMap values.
Correct Answer: D
BY Explanations “Top Java Quiz Questions”
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
China’s stock markets are some of the largest in the world, with total market capitalization reaching RMB 79 trillion (US$12.2 trillion) in 2020. China’s stock markets are seen as a crucial tool for driving economic growth, in particular for financing the country’s rapidly growing high-tech sectors.Although traditionally closed off to overseas investors, China’s financial markets have gradually been loosening restrictions over the past couple of decades. At the same time, reforms have sought to make it easier for Chinese companies to list on onshore stock exchanges, and new programs have been launched in attempts to lure some of China’s most coveted overseas-listed companies back to the country.
Telegram announces Anonymous Admins
The cloud-based messaging platform is also adding Anonymous Group Admins feature. As per Telegram, this feature is being introduced for safer protests. As per the Telegram blog post, users can “Toggle Remain Anonymous in Admin rights to enable Batman mode. The anonymized admin will be hidden in the list of group members, and their messages in the chat will be signed with the group name, similar to channel posts.”