开发者

Difference between addItem and insertItemAt method in java

What is the Difference Between addItem and inserItemAt method in java?

One thing that i have noticed while making a program is that addItem method sta开发者_开发技巧rts putting entries in the last in JComboBox. insertItemAt method pins the entry at specific position.

*Is That The Only Difference? *


It depends on the implementation of the underlying datamodel but as for the semantics, yes that would be the only difference. Here are some differences for insertItemAt:
- might throw an IndexOutOfBoundsException if the specified index is invalid
- does not select an item whereas addItem selects the inserted item if it is the only one in the list

Different implementation might do things differently and have different performance, e.g. a linked list might be faster for insertItemAt than an array based list.


Is That The Only Difference?

From the standpoint of how it affects the underlying Collection, yes.


Both insert items, the only diference is: the first insert the item in the end like a stack, and the second one inserts an item in an indicated position, obviously moving the items according to.

So basically, yes, that's the only differece

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜