arraylist - Java Array returns Null -


so when use pick string of random events returns null:

public static list<string> picknrandom(list<string> lst, int n) {     list<string> copy = new linkedlist<string>(lst);     collections.shuffle(copy);     return copy.sublist(0, n); }  static list<string> randomp; public list<string> items(){     list<string> teamlist = new linkedlist<string>();     teamlist.add("team1");     teamlist.add("team2");     teamlist.add("team3");     teamlist.add("team4");     teamlist.add("team5");     teamlist.add("team6");     list<string> randompicks = picknrandom(teamlist, 3);     randompicks = randomp;     return randompicks; }  public static void store() {     random rand = new random();     int people = rand.nextint(50) + 1;     list<string> itemsin = randomp;     system.out.println("people in store: "+people + "\nitems in store: "+itemsin); }  public static void main(string[] args) {     store();  } 

why returning null , can fix this?

in line list<string> itemsin = randomp; assign list not initialized default value null. think that's how line should like: list<string> itemsin = items(); remember change method items() static.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -