๐Ÿš€Doctor Strange's Guide to Collections in Java๐Ÿง™โ€โ™‚๏ธโœจ

๐Ÿš€Doctor Strange's Guide to Collections in Java๐Ÿง™โ€โ™‚๏ธโœจ

Code Sample Available Below ๐Ÿ‘‡


3 min read

Greetings, fellow coders! ๐Ÿš€

Today, we're diving into the mystical realm of Java Collections Framework, guided by none other than the Sorcerer Supreme himself, Doctor Strange!

๐ŸŒ€ Let's explore List, Set, and Map through the enchanting world of spells, artifacts, and portals.

๐Ÿ‘จโ€๐Ÿ’ป Ready to cast some coding magic? ๐ŸŒŸ

๐Ÿ”ฎ Library of Spells

List Imagine having access to the Sanctum Sanctorum's library filled with ancient and powerful spells!

๐Ÿ“š In Java, we can use a List to store these spells. Lists maintain the order of insertion and allow duplicates, making them perfect for our spell collection.

๐Ÿ“‹ Lists are great for keeping things in order, just like how Doctor Strange meticulously organizes his Spell-Book! ๐Ÿช„

๐ŸบArtifacts of the Sanctum Sanctorum

Set Next, let's look at the unique and powerful artifacts housed in the Sanctum Sanctorum.

๐Ÿบ To ensure no duplicates, we use a Set. Sets are perfect for collections where each item must be unique.

๐Ÿ”— Sets ensure that each artifact is one-of-a-kind, just like the mystical items Doctor Strange relies on! ๐Ÿ”ฎ

๐ŸŒŒ Portal Coordinates๐Ÿ’ซ

Map Lastly, let's navigate through the multiverse using portals!

๐ŸŒŒ A Map is perfect for storing portal coordinates, mapping dimension names to their specific locations.

๐Ÿ—บ๏ธ Maps are ideal for handling key-value pairs, ensuring Doctor Strange can always find his way through the multiverse! ๐ŸŒ 

โœจ Bonus:

Sorting the Collections! Just like organizing spells and artifacts, sorting can be magical too!

๐Ÿงน Using Collections.sort(), we can keep our lists neat and ready for any adventure.

๐Ÿ”ฎ Sorting helps keep our collections organized, ready to face any mystical threat that comes our way! ๐Ÿง™โ€โ™‚๏ธ๐Ÿ“œ

Embrace the magic of Java Collections and may your code be as powerful as the Sorcerer Supreme! ๐Ÿ’ป๐Ÿ”ฎ

#Java #Coding #CollectionsFramework #DoctorStrange #Programming #Hashnode #Medium #Tech #Automation #SoftwareEngineering #ArtificialIntelligence

๐Ÿš€๐Ÿš€Full Code Here๐Ÿš€๐Ÿš€

import java.util.*;

public class DoctorStrangeCollections {

public static void main(String[] args) {

// List - Sanctum Sanctorum's Library of Spells

List spells = new ArrayList<>();

spells.add("Winds of Watoomb");

spells.add("Crimson Bands of Cyttorak");

spells.add("Vapors of Valtorr");

spells.add("Bolts of Bedevilment");

System.out.println("Library of Spells:");

for (String spell : spells) {



// Set - Artifacts of the Sanctum Sanctorum (No duplicates allowed)

Set artifacts = new HashSet<>();

artifacts.add("Eye of Agamotto");

artifacts.add("Cloak of Levitation");

artifacts.add("Book of Vishanti");

artifacts.add("Wand of Watoomb");

artifacts.add("Eye of Agamotto"); // Duplicate entry, won't be added

System.out.println("\nArtifacts in the Sanctum Sanctorum:");

for (String artifact : artifacts) {



// Map - Portal coordinates to different dimensions

Map<String, String> portals = new HashMap<>();

portals.put("Dark Dimension", "13ยฐN, 77ยฐE");

portals.put("Mirror Dimension", "23ยฐS, 45ยฐW");

portals.put("Astral Dimension", "0ยฐ, 0ยฐ");

portals.put("Dark Dimension", "14ยฐN, 76ยฐE"); // Overwriting previous entry

System.out.println("\nPortal Coordinates:");

for (Map.Entry<String, String> portal : portals.entrySet()) {

System.out.println(portal.getKey() + ": " + portal.getValue());


// Extra - Using Collections methods


System.out.println("\nSorted Library of Spells:");

for (String spell : spells) {



List sortedArtifacts = new ArrayList<>(artifacts);


System.out.println("\nSorted Artifacts in the Sanctum Sanctorum:");

for (String artifact : sortedArtifacts) { System.out.println(artifact);




Happy coding, fellow sorcerers! ๐Ÿง™โ€โ™‚๏ธโœจ