Class File:
public class Student {
public String stu_FName;
public String stu_LName;
public String stu_ID;
}
This is the code I wrote to get inputs from the user public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter value for X");
int x = sc.nextInt();
ArrayList<Student> stuIDArray = new ArrayList<Student>(4);
while (x != 0) {
Student st = new Student();
System.out.println("Enter First Name");
st.stu_FName = sc.next();
stuIDArray.add(st);
System.out.println("Enter value fo1r X");
x = sc.nextInt();
}
When I print the size of the array after storing values using the above code, size works fine,
System.out.println(stuIDArray.size());
but when i try to print out the results in any of the following methods, it prints some code type format
for (int i=0;i<stuIDArray.size();i++){
System.out.println(stuIDArray.get(i));
}
for (Student a : stuIDArray){
System.out.println(a);
}
output :
com.company.Student@45ee12a7
com.company.Student@330bedb4
com.company.Student@45ee12a7
com.company.Student@330bedb4