Java passing Arrarylist fromm one class to another class

How to you pass an arraylist from one class to another. in the my first class i have a class call getUserSalt which return mysalt. I want to pass mysalt to the second class verifyPassword.

    public   List<User> getUserSalt(String username,byte[] password,Connection conn) {
        User usersalt=new User();
        List <User> mysalt=new ArrayList<>();
        try(PreparedStatement stmt=conn.prepareStatement("SELECT * FROM db_users WHERE  username=?")) {
            ResultSet resultSet=stmt.executeQuery();

            while ({
                return mysalt;

        }catch ( SQLException e){
            System.out.println( "error getting salt"+ e.getSQLState());


        return mysalt;
//Verify password
    public List<User> verifyPassword(String username, String password, byte[]salt){
       UserDOA a=new UserDOA();
        for(int i=0;i<a.getUserSalt();i++){



It looks like there is some naming confusion going on here. getUserSalt() and verifyPassword() are methods, not classes. I assume these methods are in different classes.

You cannot pass your mySalt result to the verifyPassword() method directlyh. This method takes a String, a String and a byte[]. Your mySalt is a List<User>. verifyPassword() actually returns a List<User> - but it doesn’t take one as a parameter.

I think you want a method that takes a List<User> and breaks each User into its name and password Strings and the ‘salt’ byte[], and then passes those details to the verifyPassword() method. Alternately change verifyPassword() so that it takes a List<User> (List<User> verifyPassword(List<User>) { }) and then in the method loop through each User as mentioned before generating the UserDOA.

Thanks, yes you are right. My bad, these methods are in two separate classes. Thanks for taking your time to reply.