A request from a noob Java beginner. I know it's a naive question, but till now I haven't found a satisfying solution. Some of the posts on stackoverflow currently either are for unweighted graphs, or involve complicated graph implementation work.
I have a set of vertices, labeled by integers 1, 2, 3, ....and some of them are linked with an undirected weighted edge (weights are integers also). I have managed to store these vertices already by using HashSet, which is convenient enough for me to manipulate (add, search, remove, etc.)
However, I have difficulty to store these edges by using built-in data structure in Java. Generally, I just want a simple built-in data structure to store edges with weight, such that I can search & select edges linked to a certain vertex quickly. I have some primary naive thoughts. For example, ArrayList<ArrayList<ArrayList>> & HashMap<int[], Integer> (thought the latter one won't work as expected, I just want to set a pair of integer of vertices for edge (a, b) as input to get its weight from the data structure) However, they are obviously inefficient to use. I don't want to use adjacency matrix since its size is large enough to be unacceptable for me.
Is such a demand feasible by simply using built-in data structure in Java? If yes, can you tell me what should I do? If not, can you come up with an implementation of graph which is easy for the work mentioned above? Thank you in advance.