Java - How to access an ArrayList of another class? -


hello i'm beginner in java , question: have first class following variables:

import java.util.arraylist;  public class numbers {     private int number1 = 50;     private int number2 = 100; } 

and have class too:

import java.util.arraylist;  public class test {     private numbers number; } 

my question here is: want store number1 & number2 variables arraylist, access arraylist class test. how can that?

import java.util.arraylist; public class numbers {    private int number1 = 50;    private int number2 = 100;    private list<integer> list;     public numbers() {        list = new arraylist<integer>();        list.add(number1);        list.add(number2);    }     public list<integer> getlist() {        return list;    } } 

and test class:

import java.util.arraylist; public class test {    private numbers number;     //example    public test() {      number = new numbers();      list<integer> list = number.getlist();      //hurray !    } } 


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -