java vector

向量类别sureCapacity()方法 (Vector Class ensureCapacity() method)

  • ensureCapacity() method is available in java.util package.

    sureCapacity()方法在java.util包中可用。

  • ensureCapacity() method is used to ensure the capacity of this Vector when required or in other words, we can say this method is used to extend the capacity of this Vector when required.

    sureCapacity()方法用于在需要时确保此Vector的容量,换句话说,可以说此方法用于在需要时扩展此Vector的容量。

    The formula of New Capacity:

    新产能的公式:

    New Capacity = old capacity + minimum capacity (min_cap)

    新容量=旧容量+最小容量(min_cap)

  • ensureCapacity() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    guaranteeCapacity()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • ensureCapacity() method does not throw an exception at the time of ensuring capacity.

    确保容量时, ensureCapacity()方法不会引发异常。

Syntax:

句法:

    public void ensureCapacity(int min_cap);

Parameter(s):

参数:

  • int min_cap – represents the required minimum capacity (min_cap).

    int min_cap –表示所需的最小容量(min_cap)。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example
// of void ensureCapacity(int min_cap) method
// of Vector
import java.util.*;
public class EnsureCapacityOfVector {public static void main(String[] args) {// Instantiates a Vector object  with
// initial capacity of "10"
Vector < String > v = new Vector < String > (10);
// By using add() method is to add the
// elements in this v
v.add("C");
v.add("C++");
v.add("JAVA");
// Display Vector Capacity
System.out.println("v.capacity(): " + v.capacity());
// By using ensureCapacity() method is to
// extend the capacity
v.ensureCapacity(20);
// Display Updated Capacity
System.out.println("v.ensureCapacity(20): " + v.capacity());
}
}

Output

输出量

v.capacity(): 10
v.ensureCapacity(20): 20

翻译自: https://www.includehelp.com/java/vector-ensurecapacity-method-with-example.aspx

java vector

java vector_Java Vector sureCapacity()方法与示例相关推荐

  1. java散列法的运用实例,Java HashMap compute() 使用方法及示例

    Java HashMap compute() 使用方法及示例 Java HashMap compute()方法计算一个新值,并将其与哈希映射中的指定键相关联. compute()方法的语法为: has ...

  2. math的用法在java中的使用,Java Math cbrt() 使用方法及示例

    Java Math cbrt() 使用方法及示例 Java Math cbrt()方法返回指定数字的立方根. cbrt()方法的语法为: Math.cbrt(double num) 注意:cbrt() ...

  3. java arraylist 方法返回值,Java ArrayList get() 使用方法及示例

    Java ArrayList get() 使用方法及示例 Java ArrayList get()方法返回指定位置存在的元素. get()方法的语法为: arraylist.get(int index ...

  4. java vector_Java Vector size()方法与示例

    java vector 矢量类size()方法 (Vector Class size() method) size() method is available in java.util package ...

  5. java vector_Java Vector elements()方法与示例

    java vector 向量类elements()方法 (Vector Class elements() method) elements() method is available in java. ...

  6. java vector_Java Vector lastElement()方法与示例

    java vector 向量类的lastElement()方法 (Vector Class lastElement() method) lastElement() method is availabl ...

  7. java kryo_Kryo框架使用方法代码示例

    Kryo框架的source已移至https://github.com/EsotericSoftware/kryo ,进入此页面,然后点击右边的Download Zip按钮,就能下载到最新版本的Kryo ...

  8. java readtimeout_Java HttpURLConnection.getReadTimeout方法代码示例

    import java.net.HttpURLConnection; //导入方法依赖的package包/类 /** * 得到响应对象 * * @param urlConnection * @retu ...

  9. Java Math toIntExact() 使用方法及示例 long转int

    Java Math toIntExact()方法从指定的long参数返回int值. toIntExact()方法的语法为: Math.toIntExact(long value) 注意:toIntEx ...

最新文章

  1. toad for oracle xpert edition,Toad for oracle 软件产品模块对比,方便大家选型
  2. 安装Realtek HD Audio Driver 失败 就是安装不上怎么办
  3. 偷天换日——新型浏览器劫持木马“暗影鼠”分析
  4. python卷积函数_python – 理解Scipy卷积
  5. gcc,make和cmake
  6. python Image 安装
  7. ROR no such file to load -- sqlite3 错误解决方法
  8. Python21天打卡Day15-21 函数+参数
  9. 基础连接已关闭解决办法_解决|罗技蓝牙键盘连接ipad后打不出字?
  10. 差分相干解调 matlab,差分相干解调
  11. “创作大师——(PyTorch)RNN”
  12. 云计算与大数据技术 第一章
  13. CRC校验原理及其C语言实现
  14. 实时云渲染有哪些优势?
  15. c语言种%*的*作用
  16. Host Context配置
  17. 完整创建 注册功能步骤
  18. php鲜花销售理论意义,鲜花销售系统(论文+源代码)论文有用
  19. 初中计算机案例交流,初中语文与信息技术整合教学案例——《爱莲说》
  20. 【财富空间】计算机起源的数学思想

热门文章

  1. 商品详情页html,天天生鲜商品详情页HTML+css
  2. css html 双面打印_从 Linux 命令行进行打印 | Linux 中国
  3. php怎么取request,PHP-如何在Guzzle中获取Request对象?
  4. java异常标记_java.lang.RuntimeException:错误:0D0680A8:asn1编码例程:ASN1_CHECK_TLEN:错误的标记...
  5. pytest测试实战 电子书_电子书丨Selenium 3+Python 3自动化测试项目实战:从菜鸟到高手...
  6. linux下qq怎么截图,ubuntu 12.04使用QQ截图安装教程
  7. Docker入门-简介
  8. JAVA知识基础(六):抽象
  9. UVA - 1339 ​​​​​​​Ancient Cipher
  10. elasticsearch存储空间不足导致索引只读,不能创建