Guest User

Untitled

a guest
Aug 29th, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. Super simple problem with ArrayList in Java
  2. public class Cliente {
  3. private static String user;
  4. private static String password;
  5. public Cliente (String usr, String pass) {
  6. user = usr;
  7. password = pass;
  8. }
  9. public String getUser() {
  10. return user;
  11. }
  12. }
  13.  
  14. public class AddToArrayList{
  15. static ArrayList<Cliente> listaClientes = new ArrayList<Cliente>();
  16.  
  17. public static void main(String[] args) throws IOException {
  18.  
  19. Cliente c1 = new Cliente("pepe","pepe1");
  20. Cliente c2 = new Cliente("jose","jose1");
  21. Cliente c3 = new Cliente("edu","edu1");
  22. listaClientes.add(c1);
  23. listaClientes.add(c2);
  24. listaClientes.add(c3);
  25.  
  26. printArraList();
  27. }
  28.  
  29. public static void printArraList() throws IOException {
  30. for (Cliente c : listaClientes) {
  31. System.out.println(c.getUser());
  32. }
  33. }
  34.  
  35. private static String user;
  36. private static String password;
  37.  
  38. private String user;
  39. private String password;
Add Comment
Please, Sign In to add comment