Basic Data Structures in Java— Arrays, Lists, Sets, Queue, and Maps

Photo by Procreator UX Design Studio on Unsplash
String[] topThreeHobbies = {“Eat”, “Sleep”, “Code”};
List<String> bucketList = new ArrayList<>();bucketList.add("Visit Alaska");bucketList.add("Visit Hawaii");bucketList.add("Visit China");bucketList.set(2, "Visit Japan");   //replace visit Chinafor (String list : bucketList) {System.out.println(list);}
Set<String> codingJournal = new LinkedHashSet<>();codingJournal.add("2/10/2021");codingJournal.add("5/11/2021");codingJournal.add("7/31/2021");//Check whether have studied on that dateSystem.out.println(codingJournal.contains("7/30/2021"));    //falseSystem.out.println(codingJournal.contains("7/31/2021"));    //true//Traversing the LinkedHashSetIterator<String> trace = codingJournal.iterator();while(trace.hasNext()) {                 //elements iterate in insertion orderSystem.out.println(trace.next());   //printout dates that have logged for learning to code}
Map<String, ArrayList<String>> BU = new HashMap<>();ArrayList<String> languages = new ArrayList<>();languages.add("Java");languages.add("SQL");ArrayList<String> classes = new ArrayList<>();classes.add("CS520");classes.add("CS669");BU.put("Languages", languages);BU.put("Classes", classes);System.out.println(BU.get("Languages"));    //[Java, SQL]System.out.println(BU.get("Classes"));  //[CS520, CS669]

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store