I have a constructor here with two strings:
public class person
{
String first;
String last;
public person (String first, String last)
{
this.first = first;
this.last = last;
}
public String toString()
{
String result = first + "\n";
result += last + "\n";
return result;
}
}
And a main method that creates two objects of the constructor:
import java.util.ArrayList;
public class k
{
public static void main (String[] args)
{
ArrayList<person> list = new ArrayList<person>();
person ken = new person ("Ken", "Smith");
person ben = new person ("Ben", "Smith");
list.add (ken);
list.add (ben);
System.out.println (list.get(0));
}
}
Right now the code prints Ken Smith. My question is: How would I get it to print just Ken instead of Ken Smith?