Java array entries

I need to get a variable type that has 3 types of values, the only way I know is with Records, but I know that in Java there is no such type as Records, but ArrayList, but I don’t understand ...

My result should be: (I don’t know how it will look in Java, so I am showing in a different style)

TData = Record
     Username : String;
     UserID : Int ;
     RowID : Int;
   end;
users : array[1..10] of TData;

for(int i = 1; i < rowCount; i++){
   TData.Username[i] = rs.GetString("Name");
   TData.UserID[i] = rs.GetInt("UserID");
   TData.RowID[i] = row;
}

Any suggestions on how to do something like this? Do I really need ArrayList?

Thanks for the help, in the end I combined and got this result, it works fine:

class MyData {
        private String userName;
        private int userID;
        private int RowID;


        public MyData(String userName, int userID, int RowID) {
            this.userName = userName;
            this.userID = userID;
            this.RowID = RowID;
        }

        public String getUserName() {
            return userName;
        }

        public int getUserID() {
            return userID;
        }
        public int getRowID() {
            return RowID;
        }
    }

    public void AList(){
        ArrayList<MyData> users = new ArrayList<>();
        try{
            conn = DBConnection.DBConnector();
            pst = conn.prepareStatement("SELECT * FROM TableUserData");
            rs = pst.executeQuery();
            row = 0;
            while (rs.next()) {
                users.add(new MyData(rs.getString("User_name"), rs.getInt("ID"), row));
                row++;
                }
            for (MyData tmp : users) {
                JOptionPane.showMessageDialog(null, "Users: " + tmp.getUserName() + " row: " + rtmp.getRowID());

            }

        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Arraylist error: " + e);
        }

    }
+4
source share
2 answers

You mix things.

An ArrayList "" , .

( ) .

Java - ,

class MyData {
    private String userName;
    private int userID;
    private int rowID;

    public MyData(String userName, int userID, int rowID) {
        this.userName = userName;
        this.userID = userID;
        this.rowID = rowID;
    }

    public String getUserName() {
        return userName;
    }

    public int getUserID() {
        return userID;
    }

    public int getRowID() {
        return rowID;
    }
}

ArrayList<MyData> users = new ArrayList<>();

while (rs.next()) {
   users.add(new MyData(rs.GetString("Name"), rs.GetInt("UserID"), rs.GetInt("RowID")));
}
+6

-

int salary;
float bonus;
char YesOrNo = 'Y';  

salary, bonus YesOrNo , int, float char - . salary int, bonus - float. int, float, char - java.

object oriented , - java. , Record -

public class Record {
    private String userName;
    private int userId; 
    private int rowId;

    public Record(String userName, int userId, int rowId){
      this.userName = userName;
      this.userId = userId;
      this.rowId
    }

    //getter and setter methods  if required
}  

, / Record -

Record aRecord = new Record("user001", 1, 1);

OOP - Record . aRecord Record.

ArrayList Record -

List<Record> recordList = new ArrayList<Recored>();
+1

All Articles