I have a small problem with printing out strings that are stored in an object. The object is stored in an ArrayList.
I have three clases that I use im my program:
Friend Class:
package one;
public class Friend implements InterfaceFriend {
private String name;
private String email;
private String phone;
public Friend(String name, String phone, String email) {
// TODO Auto-generated constructor stub
}
@Override
public String getPhone() {
return phone;
}
@Override
public String getEmail() {
return email;
}
@Override
public String getName() {
return name;
}
@Override
public void setPhone(String phone1) {
phone1 = phone;
}
@Override
public void setEmail(String email1) {
email1 = email;
}
@Override
public void setName(String name1) {
name1 = name;
}
}
FriendInterface:
package one;
public interface InterfaceFriend {
String getPhone(); // Returns phone number.
String getEmail(); // Returns email.
String getName(); // Returns name.
void setPhone(String phone); // Sets phone.
void setEmail(String email); // Sets email.
void setName(String name); // Sets name.
}
and Test Class:
package one;
import java.util.ArrayList;
import java.util.List;
public class FriendTest {
static List<Friend> friends;
static Friend friend;
public static void main(String args[]) {
friends = new ArrayList<Friend>();
friend = new Friend("Jane Doe", "085-5555555", "[email protected]");
friends.add(friend);
friend = new Friend("John Doe", "085-1111111", "[email protected]");
friends.add(friend);
friend = new Friend("Paul Weller", "085-3333333", "[email protected]");
friends.add(friend);
System.out.println("Friends added to list:");
System.out.println(friends.toString());
}
}
The problem is that when I am running the System.out.println(friends.toString());from the Test Class i am getting this:
Friends added to list:
[one.Friend@38f0b51d, one.Friend@4302a01f, one.Friend@615e7597]
Instead the Strings with the values that I want. Any help appreciated.
toString()method in yourFriendclass.toString()you also need to make sure yourFriend(String,String,String)constructor is implemented - because that seems to be blank.