Vector how might looks in Java : <pre><code>vector&lt;int&gt; g[100001];
main() {
    int n, m, v1, v2;
    cin &gt;&gt; n &gt;&gt; m;
    for(int i = 1; i &lt;= m; i++) {
        cin &gt;&gt; v1 &gt;&gt; v2;
        g[v1].push_back(v2);
        g[v2].push_back(v1);
    }
}
</code></pre>

<p>Here is code in C++. <strong>I was wondering how can be implemented this part of using Collections in java</strong></p>

<pre><code> g[v1].push_back(v2);
 g[v2].push_back(v1);
</code></pre>
