Advertisement
Guest User

dynamicArrayAppending

a guest
Aug 8th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. package dynamicList;
  2. import java.util.ArrayList;
  3. public class listAppend {
  4.     protected String username;
  5.     protected String password;
  6.     public listAppend(String username, String password) {
  7.         username = this.username;
  8.         password  = this.password;
  9.         //My goal was to use append the password parameter of every object created, but null kept coming back as value.
  10.         //usernameList.add(this.password);
  11.        
  12.     }
  13.     //Instead I tried invoking method on specific objects statically after instantiation and it was still null value.
  14.     public void addPass() {
  15.         usernameList.add(this.password);
  16.     }
  17.    
  18.     static ArrayList<String> usernameList = new ArrayList<String>();
  19.     public String getusername() {
  20.         return username;
  21.     }
  22.     //Just a test to see if password wouldn't print null anymore.
  23.     public void printing() {
  24.         System.out.print(password);
  25.     }
  26.  
  27.     public static void main(String[] args) {
  28.         // TODO Auto-generated method stub
  29.         //creating object with arguments to be stored as values, right?
  30.         listAppend Kelly = new listAppend("Kelly", "12321");
  31.         System.out.println(Kelly.password);
  32.         Kelly.addPass();
  33.         System.out.println(usernameList);
  34.         //Only going through and assigning it statically seemed to return value as desired.
  35.         //Kelly.password = "920928";
  36.        
  37.  
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement