arrays - How to get another Class ArrayList Java? -


i have 2 classes in java. first 1 has functional code. second 1 uses arraylists.

how can arraylist values first one?

i new java , programming.

if arraylist instance variable (it's been defined outside of method, make local variable) make public , visible other class. not practise, however. speaking, make arraylist private , write getter method returns reference arraylist. e.g.

//declare @ top of class list<?> mylist = new arraylist<>();   public list<?> getmylist(){     return mylist; } 

assuming arraylist property of yourclass, access in method of yourotherclass need create instance of yourclass:

private void somemethodinyourclass(){      yourclass yourclass = new yourclass();      list<?> yourlist = yourclass.getmylist(); } 

having said that, however, seem getting ahead of bit. example above basic demonstration of oop in java, touches upon generics , collections, suspect not quite ready yet. decent beginner's book on java - there loads - , bring speed before getting in deep.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -