Advertisement
JVFabia

Clase3-eColecciones

Sep 25th, 2020
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. package org.forge;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7.  
  8. public class Main {
  9.  
  10.     public static void main(String[] args) {
  11.     // write your code here
  12.         // Lista
  13.         List<Integer> numeros = new ArrayList<>();
  14.         numeros.add(3);
  15.         numeros.add(24);
  16.         numeros.add(13);
  17.         numeros.add(2);
  18.         numeros.add(35);
  19.         System.out.println(numeros);
  20.         System.out.println(invertirLista(numeros));
  21.         // Diccionario
  22.         Map<String, String> nombres = new HashMap<>();
  23.         nombres.put("Alyson", "Jimenez");
  24.         nombres.put("Jorge", "Natera");
  25.         nombres.put("Nisser", "Argueta");
  26.         nombres.put("William", "Rodriguez");
  27.         System.out.println(nombres);
  28.         System.out.println(invertirDiccionario(nombres));
  29.     }
  30.  
  31.     static Map<String, String> invertirDiccionario(Map<String, String> dicc){
  32.         Map<String, String> resultado = new HashMap<>();
  33.         for (String llave: dicc.keySet() ){
  34.             resultado.put(dicc.get(llave), llave);
  35.         }
  36.         return resultado;
  37.     }
  38.  
  39.     static List<Integer> invertirLista(List<Integer> lista){
  40.         List<Integer> resultado = new ArrayList<>();
  41.         for (int i = lista.size() -1 ; i >=0  ; i--) {
  42.             resultado.add(lista.get(i));
  43.         }
  44.         return resultado;
  45.     }
  46.  
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement