public static int[][] toAdjList(IAtomContainer container) {

        if (container == null) throw new NullPointerException("atom container was null");

        int n = container.getAtomCount();

        int[][] graph = new int[n][DEFAULT_DEGREE];
        int[] degree = new int[n];

        for (IBond bond : container.bonds()) {

            int v = container.indexOf(bond.getBegin());
            int w = container.indexOf(bond.getEnd());

            if (v < 0 || w < 0)
                throw new IllegalArgumentException("bond at index " + container.indexOf(bond)
                        + " contained an atom not pressent in molecule");

            graph[v][degree[v]++] = w;
            graph[w][degree[w]++] = v;

            // if the vertex degree of v or w reaches capacity, double the size
            if (degree[v] == graph[v].length) graph[v] = copyOf(graph[v], degree[v] * 2);
            if (degree[w] == graph[w].length) graph[w] = copyOf(graph[w], degree[w] * 2);
        }

        for (int v = 0; v < n; v++) {
            graph[v] = copyOf(graph[v], degree[v]);
        }

        return graph;
    }
public static int [ ] [ ] toAdjList ( IAtomContainer container ) { if ( container == null ) throw new NullPointerException ( "atom container was null" ) ; int n = container . getAtomCount ( ) ; int [ ] [ ] graph = new int [ n ] [ DEFAULT_DEGREE ] ; int [ ] degree = new int [ n ] ; for ( IBond bond : container . bonds ( ) ) { int v = container . indexOf ( bond . getBegin ( ) ) ; int w = container . indexOf ( bond . getEnd ( ) ) ; if ( v < 0 || w < 0 ) throw new IllegalArgumentException ( "bond at index " + container . indexOf ( bond ) + " contained an atom not pressent in molecule" ) ; graph [ v ] [ degree [ v ] ++ ] = w ; graph [ w ] [ degree [ w ] ++ ] = v ; if ( degree [ v ] == graph [ v ] . length ) graph [ v ] = copyOf ( graph [ v ] , degree [ v ] * 2 ) ; if ( degree [ w ] == graph [ w ] . length ) graph [ w ] = copyOf ( graph [ w ] , degree [ w ] * 2 ) ; } for ( int v = 0 ; v < n ; v ++ ) { graph [ v ] = copyOf ( graph [ v ] , degree [ v ] ) ; } return graph ; }
Create an adjacent list representation of the {@literal container}.

@param container the molecule
@return adjacency list representation stored as an {@literal int[][]}.
@throws NullPointerException     the container was null
@throws IllegalArgumentException a bond was found which contained atoms
not in the molecule