0

I am trying to add create two ArrayList of vertices (setA, setB) which will store the stores for comparing them late how ever I am unable to add vertices to the arraylist.

here is the code

import java.util.*;


public class BipartiteGraph<Vertex> {

    private String strName;
    ArrayList<Vertex>[] vertexList;

    public BipartiteGraph(){

        vertexList = new ArrayList[2];
        vertexList[0] = new ArrayList<Vertex>();
        vertexList[1] = new ArrayList<Vertex>();
        Scanner vertexInput = new Scanner(System.in);
        int vertex;
        vertex = vertexInput.nextInt();
        for(int i = 0; i < 10; i++){
            vertexList[0].add(vertexInput.nextInt());
        }
    }
}

Also if someone could guide me if I am in the right direction.

1
  • You are trying to add an int to an ArrayList that contains Vertexes. Commented Nov 24, 2013 at 21:24

1 Answer 1

1

You are trying to add int variable into the container of Vertex objects. Assuming, that your Vertex has a constructor accepting int you should rather use:

vertexList[0].add(new Vertex(vertexInput.nextInt()));
Sign up to request clarification or add additional context in comments.

2 Comments

how can I instantiate the vertex here?
simply define the constructor accepting int, like: public Vertex(int v){ .... }`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.