English 中文(简体)
我们是否应该避免Next(Next)在一台拖车上出现?
原标题:Should we avoid hasNext() call in an Iterator?

难道不宜使用电梯。

例如,我要对名单的每个要素设定价值。 我可以使用以下代码,或使其更容易读用。

int size = list.size();
ListIterator<? super T> itr = list.listIterator();
for (int i=0; i<size; i++) {
     itr.next();
     itr.set(obj);
}

我不是这样写的。

for (ListIterator<? super T> itr = list.listIterator(); itr.hasNext(); ) {
    itr.next();
    itr.set(obj);
}
最佳回答
问题回答

其实,当NetBeans重新支持你使用电梯时,他们就这样做。

for-each:

for (T object : list) {
}

循环器型:

for (Iterator<T> it = list.iterator(); it.hasNext();) {
    T object = it.next();
}

我认为,在花招时使用Next(Next)是完全的。

没有关于不使用<条码>的的建议。

索引表只有三种方法:add,removehasNext

同样,从清洁法看,第二种方法比第一种方法好得多。

在使用探测器时,你应始终采用Next(Next)方法。 否则,在使用下一个(a)方法时,你可以进入一个“新锡”。

当然,你应当使用<代码>hasNext(),但仅用于ite over a Collection,而不是用于收集资料。 为了填充收集工作,关于收集工作的工作,而不是在收集工作中进行,并read<>em>从收集中获得for loop, 详见@JMelnik。

www.un.org/spanish/ecosoc 收集

Collection<MyObject> list = ...;
while (something) {
    list.add(myObject);
}

www.un.org/spanish/ecosoc 查阅

for (MyObject myObject : list) {
    ...
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...