I am trying to take in someones first name and last name, and then take those two Strings
and put them into one ArrayList
together.
I am able to take in the two Strings
, but the problem is I can't output them.
I have two classes as follows:
import java.util.ArrayList;
import java.util.Scanner;
public class TakeInName {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<Names> studentNames = new ArrayList<Names>();
Names newName = new Names();
newName.firstName = scan.nextLine();
newName.lastName = scan.nextLine();
studentNames.add(newName);
Names item = studentNames.get(0);
System.out.print(item);
}
}
and second:
public class Names {
String lastName;
String firstName;
}
I am not even sure if I made this second class right to be able to do anything with it? Maybe that is my problem?
When I run this code the output I get is:
Names@5c647e05
Maybe that is the memory position?
Any help is appreciated, thank you.