Java 如何打印ArrayList<;整数>;在哈希集中<;ArrayList<;整数>>;?

Java 如何打印ArrayList<;整数>;在哈希集中<;ArrayList<;整数>>;?,java,Java,如何打印HashSet>类型的索引 代码如下: HashSet<ArrayList<Integer>> possibleRoutes; 该程序建议将可能的结果强制转换为列表,因为它们不是同一类型,因此会对问题产生更多错误。那么,如何打印哈希集的索引,例如ArrayList?如果您想了解如何迭代哈希集,这可能会对您有所帮助 HashSet<ArrayList<Integer>> possibleRoutes = new HashSet<A

如何打印HashSet>类型的索引

代码如下:

HashSet<ArrayList<Integer>> possibleRoutes;

该程序建议将可能的结果强制转换为列表,因为它们不是同一类型,因此会对问题产生更多错误。那么,如何打印哈希集的索引,例如
ArrayList?

如果您想了解如何迭代哈希集,这可能会对您有所帮助

  HashSet<ArrayList<Integer>> possibleRoutes = new HashSet<ArrayList<Integer>>();

  Iterator<ArrayList<Integer>> possList  =possibleRoutes.iterator();

  /* here u can't take out by index, hasset 
    makes no guarantees as to the iteration order of the set*/

  ArrayList<Integer>main = possList.next();  //but can loop through it by next which gives ArrayList<integer>
  for(Integer m : main)
 { System.out.println(m); }
HashSet-possibleRoutes=new-HashSet();
迭代器possList=possibleRoutes.Iterator();
/*哈塞特,这里你不能按索引取出
不保证集合的迭代顺序*/
ArrayListmain=possList.next()//但是可以通过下一步遍历它,这将给出ArrayList
for(整数m:main)
{System.out.println(m);}

您的问题一点也不清楚。你需要遍历你的集合吗?我需要的是在HashSet中打印一个ArrayList。好的。什么阻止了你?你知道如何找到你需要的吗?System.out.println(possibleRoutes.indexOf(indexOfMinDistance))不起作用。错误是:“类型HashSet的方法indexOf(int)未定义”,我不知道如何解决这个问题。
Set
没有索引,除非它是
SortedSet
,而
HashSet
没有索引。
  HashSet<ArrayList<Integer>> possibleRoutes = new HashSet<ArrayList<Integer>>();

  Iterator<ArrayList<Integer>> possList  =possibleRoutes.iterator();

  /* here u can't take out by index, hasset 
    makes no guarantees as to the iteration order of the set*/

  ArrayList<Integer>main = possList.next();  //but can loop through it by next which gives ArrayList<integer>
  for(Integer m : main)
 { System.out.println(m); }