0

I created a simple **Node.java** class, where each Node instance has an

1-id variable of type int

2-Neighborlist of type Arraylist

I wrote a code that gives me a random network, made of 200 nodes, and each node can have up to 55 neighbors.

```
for(i=0; i <200; i++ ) // this is to generate 200 nodes
{
Node n = new Node();
n.id (i);
for (j=0; j<10; j++) // to put an upper bound on the number of neighbors
{
idx= randomGenerator.nextInt(200);
if (idx>=50 && idx!=i)) // 50 is a random number that ive chosen
{
// Add this node to the one hop neighbors of i
n.Neighborlist.add(idx);
}
//Add node i to the network
network_LN.add(n);
}// end
```

The problem is that this code might produce nodes that have duplicates neighbors. Is there an efficient way to prevent duplicates in the neighbor list of each node ? i was thinking to loop over the neighbor list before adding an idx and make sure that it is not there before adding it...but is there any more efficient way to do that ?