Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- write a java program that stores names of 3
- students (alice, bob, james) in an array and
- display them
- - use list
- - use Set
- ------------------------------------------------------------------
- create an array list polymorphically
- Before java 5
- List names = new ArrayList(); // no specific data type
- // Using Generics
- List<Integer> names = new ArrayList<Integer>();
- /* Wrapper classes : allows you to use primitive types as objects
- - int = Integer
- - float = Float
- - String = String
- -----------------------------------------------------------------
- Difference between sets and lists
- - sets do not preserve the order of elements
- - no duplicates
- - lists is the opposite of sets
- -----------------------------------------------------------------
- Maps store elements as pairs (key => value), unique pairs
- e.g: Create a map to store countries and their capitals
- rwanda => kigali
- kenya => nairobi
- ------------------------------------------------------------------
- ORM : object relational mapping
- technology that allows you to map classes to database tables
- public class BankAccount {} java
- create table bank_account(); sql
- ------------------------------------------------------------------
- MINECOFIN / IFMIS
- - Business Analyst : analysis, design
- - Developer : java, coding
- - System Admins : linux
- - System Administration
- - Bash Programming, task automation
- - Network Administration
- - Database Admins : postgresql, oracle
- - performance tuning (index, partitioning, replica)
- - Support Team
- */
- import java.util.Set;
- import java.util.HashSet;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Collections;
- import java.util.Map;
- import java.util.HashMap;
- public class MyClass {
- public static void main(String ... args) {
- String[] names1 = new String[3];
- List<String> names2 = new ArrayList<>();
- Set<String> names3 = new HashSet<>();
- Map<String, String> countries = new HashMap<>(); // jdk 8
- names1[0] = "alice";
- names1[1] = "bob";
- names1[2] = "james";
- names2.add("alice");
- names2.add("bob");
- names2.add("james");
- names3.add("alice");
- names3.add("bob");
- names3.add("james");
- countries.put("rwanda", "kigali"); // entries
- countries.put("kenya", "nairobi");
- countries.put("congo", "kinshasa");
- Collections.sort(names2);
- for (String name: names) {
- System.out.println(name);
- }
- System.out.println(countries.get("rwanda"));
- Set<String> keys = countries.keySet();
- System.out.println(keys);
- System.out.println("Country\tCapital");
- for (String key : keys) {
- System.out.println(key);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment