0

i have been asked to create a method that is capable of inserting a "Person" class into an ArrayList of persons. but all it says is that the types are incompatible. starting to think that the add method might not work in this situation. any advise would be greatly appreciated! thank you in advance.

import java.util.ArrayList;

public class DikuPlus
{
    private Person person;
    private ArrayList<Person> network;
    
    public void DikuPlus(ArrayList<Person> network)
    {
        this.network = network;
    }
    
    public ArrayList<Person> addPerson(Person person)
    {
        this.network = network.add(person);
    }
}

Edited by Mehnad: incompatible type arraylist person

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Ezzaral
Featured Replies
  • 1
    Ezzaral 2,714   5 Years Ago

    Look up the return type of ArrayList.add(). Why are you trying to assign that to your ArrayList variable? Read More

1

Look up the return type of ArrayList.add(). Why are you trying to assign that to your ArrayList variable?

0

would this solve the problem? and thank you for being so fast, once again:)

import java.util.ArrayList;

public class DikuPlus
{

    private ArrayList<Person> network;
    
    public void addPerson(Person person)
    {
        network.add(person);
    }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.