Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is a Vector subclass

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "what is the Vector subclass". In the daily operation, I believe that many people have doubts about what is the Vector subclass. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what is the Vector subclass?" Next, please follow the editor to study!

Vector subclass

Vector is a primitive ancient program class that was provided at JDK1.0. By JDK 1.2, because many developers have become accustomed to using Vector, and many system classes are also implemented based on Vector, considering the extensiveness of their use, the class set framework retained it and let it implement an additional List interface to observe the definition structure of Vector:

Public class Vectorextends AbstractListimplements List, RandomAccess, Cloneable, Serializable

The inheritance structure is the same as ArrayList, so the inheritance structure of this class is as follows.

Vector inheritance structure

Example: the Vector class uses

Import java.util.List;import java.util.Vector;public class JavaAPIDemo {public static void main (String [] args) throws Exception {List all = new Vector (); all.add ("Hello"); all.add ("Hello"); all.add ("Wolrd"); all.add ("MLDN"); all.forEach (System.out::println); / / Hello Hello World MLDN}}

You can take a closer look at the Vector class implementation:

Public Vector () {this (10);} public Vector (int initialCapacity) {this (initialCapacity, 0);} public Vector (int initialCapacity, int capacityIncrement) {super (); if (initialCapacity < 0) throw new IllegalArgumentException ("Illegal Capacity:" + initialCapacity); this.elementData = new Object [initialCapacity]; this.capacityIncrement = capacityIncrement;}

If the Vector class uses a no-parameter construction method, it must open a 10-length array by default, and the rest of the implementation operation is the same as ArrayList. Through the analysis of the source code, we can find that the operation methods in the Vector class all use synchronized synchronous processing, but ArrayList does not do the synchronous processing, so the methods in the Vector class are thread-safe when accessing by multiple threads, but the performance is not as high as ArrayList.

At this point, the study of "what is a Vector subclass" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report