Hello! I use library Jung http://jung.sourceforge.net to create a graph. In the process of adding vertices, the graph Jung checks if this vertex is there or not, if not, it adds. That is, if you write Graph<Integer, String> g = new UndirectedSparseGraph<Integer, String>(); g.addVertex(1); g.addVertex(1); Graph<Integer, String> g = new UndirectedSparseGraph<Integer, String>(); g.addVertex(1); g.addVertex(1); Then add only one vertex with integer value 1. Now I need to create a graph, but instead of simple types, it should consist of my classes. Now, if Graph<MyVertex, MyEdge> g = new UndirectedSparseGraph<MyVertex, MyEdge>(); g.addVertex(new MyVertex(1, 255)); g.addVertex(new MyVertex(1, 255)); Graph<MyVertex, MyEdge> g = new UndirectedSparseGraph<MyVertex, MyEdge>(); g.addVertex(new MyVertex(1, 255)); g.addVertex(new MyVertex(1, 255)); It will add two instances of the class, which, logically, are duplicates. To avoid this, I wrote a function that, throughout the ArrayList of MyVertex, searches for a class with the same fields and deletes it. The question is, does JUNG have ready-made solutions for this problem? If not, how effectively can you use a search in an ArrayList if its size is about 10,000?

  • Are the equals and hashCode methods redefined in your classes? Why not use Set instead of List? If you use the List only to find duplicates, then look in the Jung documentation (or source code) and see what you can do to get the library to take care of deletion. - a_gura
  • hashCode did not override. When inheriting, he does not ask to be redefined. - stream2006
  • @ stream2006 Who does not ask? Is the code talking to you? If you override equals, you should always override hashCode. - a_gura

0