简体   繁体   中英

What's the difference between the java vector methods set() and setElementAt()?

在Google上找不到任何真实答案。

The documentation states it clearly:

[setElementAt] is identical in functionality to the set(int, E) method (which is part of the List interface). Note that the set method reverses the order of the parameters, to more closely match array usage. Note also that the set method returns the old value that was stored at the specified position.

http://download.oracle.com/javase/6/docs/api/java/util/Vector.html

EDIT : How I search Google for Java documentation is pretty simple. I type java 6 api String (replace String with whatever class you are wondering about) and it's usually the first hit.

set returns the original object at the given position.

Also, the set method appeared when the Vector class was retrofitted to conform to the List interface.

The set() method was introduced when the Java 1.2 collections replaced legacy classes like Vector in 1998. They do the same thing, but perhaps its time to start using List if you can. (which just has set())

Have you read the API documentation ? These are the same, with the exception that the set method returns the object previously at the specified position.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM