如何解决ListIterator.PreviousIndex 返回一个单元素整数数组而不是 Int?
我正在编写一个程序,其中有一次,我正在遍历“存储桶”列表(嵌套的字符串列表)。这样做时,我需要跟踪存储桶中特定元素的索引。
为此,我求助于创建第二个 2D 列表对象,其中每个内部列表存储需要跟踪的元素的 int 索引值。
因为第二个列表稍后会在我的代码中进行排序,所以我想将每个内部列表的第一个元素专用于存储它负责跟踪其中元素的存储桶的索引。
我想我可以通过使用列表迭代器的“prevIoUsIndex()”方法来做到这一点,因为它说它返回一个 int 值。但相反,它返回一个包含我想要的 int 的 1 元素 int 数组,而不仅仅是 int 本身。这完全弄乱了我的代码,当它以这种方式存储时,我似乎无法访问该元素。
public static ArrayList<List<Integer>> isItPossible(String word,LinkedList<List<String>> buckets) {
ListIterator<List<String>> bucketIterator;
ListIterator<String> wordIterator;
List<String> bucket;
ArrayList<List<Integer>> enemies;
enemies = new ArrayList<List<Integer>>();
bucketIterator = buckets.listIterator();
while(bucketIterator.hasNext()) {
bucket = bucketIterator.next();
wordIterator = bucket.listIterator();
enemies.add(new ArrayList<Integer>());
enemies.get(enemies.size() - 1).add(bucketIterator.prevIoUsIndex()); //adds a list with the element I need,but I just need the element,not the list????
while(wordIterator.hasNext()) {
if(!isCompatible(word,wordIterator.next())) {
enemies.get(bucketIterator.prevIoUsIndex()).add(wordIterator.prevIoUsIndex());
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。