title: BFS traversal of all paths in graph using adjacency list
body: <p>I am currently trying to traverse all paths from source to destination in a graph which uses adjacency matrix. I have been trying to do it in BFS way.Thanks for the help. I am getting only one path. How do I get to print other paths as well ?</p>
  
  <pre><code>public class AllPossiblePaths {
      static int v;
      static ArrayList&lt;Integer&gt; adj[];
  
      public AllPossiblePaths(int v) {
          this.v = v;
          adj = new ArrayList[v];
          for (int i = 0; i &lt; v; i++) {
              adj[i] = new ArrayList&lt;&gt;();
          }
      }
  
      // add edge from u to v
      public static void addEdge(int u, int v) {
          adj[u].add(v);
      }
  
      public static void findpaths(int source, int destination) {
          LinkedList&lt;ArrayList&lt;Integer&gt;&gt; q = new LinkedList&lt;&gt;();
          boolean visited[] = new boolean[v];
  
          LinkedList&lt;Integer&gt; queue = new LinkedList&lt;Integer&gt;();
  
          queue.add(source);
          visited[source] = true;
          ArrayList&lt;Integer&gt; localPath = new ArrayList&lt;&gt;();
          while (!queue.isEmpty()) {
              // Dequeue a vertex from queue and print it
              int src = queue.poll();
              if (!localPath.contains(src)) {
                  localPath.add(src);
              }
              if (src == destination) {
                  System.out.println(localPath);
                  localPath.remove(localPath.size() - 1);
                  visited[src] = false;
              }
  
              Iterator&lt;Integer&gt; i = adj[src].listIterator();
              while (i.hasNext()) {
                  int n = i.next();
                  if (!visited[n]) {
                      queue.add(n);
                  }
              }
          }
      }
  }
  </code></pre>