java sublist_Java Vector subList()方法与示例

java sublist

向量类subList()方法 (Vector Class subList() method)

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

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

  • subList() method is used to return a set of sublist [it returns all those elements exists in a given range starting index (st_index) and ending index (en_index) and here st_index is inclusive whereas en_index is exclusive].

    subList()方法用于返回一组子列表[它返回给定范围内存在的所有那些元素,即开始索引(st_index)和结束索引(en_index),其中st_index是包含的,而en_index是排除的]。

  • subList() 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.

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

  • subList() method may throw an exception at the time of returning sublist.

    subList()方法在返回子列表时可能会引发异常。

    • IndexOutOfBoundsException: This exception may throw when the second parameter is not in a range.IndexOutOfBoundsException :当第二个参数不在范围内时,可能引发此异常。
    • IllegalArgumentException: This exception may throw when the second argument is not valid.IllegalArgumentException :当第二个参数无效时,可能引发此异常。

Syntax:

句法:

    public List subList(int st_index, int en_index);

Parameter(s):

参数:

  • int st_index – represents the starting position of the returned sublist.

    int st_index –表示返回的子列表的起始位置。

  • int en_index – represents the ending position of the returned sublist.

    int en_index –表示返回的子列表的结束位置。

Return value:

返回值:

The return type of the method is List, it returns all the element in a given range and elements are viewed in a List.

方法的返回类型为List ,它返回给定范围内的所有元素,并在List中查看元素。

Example:

例:

// Java program to demonstrate the example 
// of List subList(int st_index, int en_index)
// method of Vector 
import java.util.*;
public class SubListOfVector {
public static void main(String[] args) {
// Instantiates a Vector object  with
// initial capacity of "10"
Vector < String > v = new Vector < String > (10);
List arr_l = new ArrayList();
// By using add() method is to add the
// elements in this v
v.add("C");
v.add("C++");
v.add("JAVA");
// By using add() method is to add the
// elements in this arr_l
arr_l.add("SFDC");
// Display Vector and ArrayList
System.out.println("v: " + v);
System.out.println("arr_l: " + arr_l);
// By using subList() method is to
// return the sublist, starting at one
// endpoint and ending at other endpoint
arr_l = v.subList(0, 2);
// Display updated arr_l
System.out.println("v.subList(0,2): " + arr_l);
}
}

Output

输出量

v: [C, C++, JAVA]
arr_l: [SFDC]
v.subList(0,2): [C, C++]

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

java sublist

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/544217.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

单例模式 4 种经典实现方法

0.前言 如果你去问一个写过几年代码的程序员用过哪些设计模式&#xff0c;我打赌&#xff0c;90%以上的回答里面会带【单例模式】。甚至有的面试官会直接问&#xff1a;说一下你用过哪些设计模式&#xff0c;单例就不用说了。你看&#xff0c;连面试官都听烦了&#xff0c;火爆…

CSRF简单介绍及利用方法-跨站请求伪造

0x00 简要介绍 CSRF&#xff08;Cross-site request forgery&#xff09;跨站请求伪造&#xff0c;由于目标站无token/referer限制&#xff0c;导致攻击者可以用户的身份完成操作达到各种目的。根据HTTP请求方式&#xff0c;CSRF利用方式可分为两种。 0x01 GET类型的CSRF 这种类…

java setsize_Java Vector setSize()方法与示例

java setsize向量类setSize()方法 (Vector Class setSize() method) setSize() method is available in java.util package. setSize()方法在java.util包中可用。 setSize() method is used to set the new size of this vector and when new size (n_size) > current size …

虾皮二面:什么是零拷贝?如何实现零拷贝?

前言 零拷贝是老生常谈的问题啦&#xff0c;大厂非常喜欢问。比如Kafka为什么快&#xff0c;RocketMQ为什么快等&#xff0c;都涉及到零拷贝知识点。最近技术讨论群几个伙伴分享了阿里、虾皮的面试真题&#xff0c;也都涉及到零拷贝。因此本文将跟大家一起来学习零拷贝原理。1.…

设计模式2:工程模式(1)

什么是工厂模式? 提供一个创建一系列或相互依赖对象的接口&#xff0c;而不需指定它们具体的类。 通俗的讲就是定义了多个产品的类&#xff0c;且只有一个工厂类&#xff0c;而这个工厂类根据需求的不同&#xff0c;可以产生不同产品类的对象。 作用:主要为创建对象提供过度接…

java indexof_Java Vector indexOf()方法与示例

java indexof向量类indexOf()方法 (Vector Class indexOf() method) Syntax: 句法&#xff1a; public int indexOf(Object ob);public int indexOf(Object ob, int indices);indexOf() method is available in java.util package. indexOf()方法在java.util包中可用。 indexO…

各大框架都在使用的Unsafe类,到底有多神奇?

前言 几乎每个使用 Java开发的工具、软件基础设施、高性能开发库都在底层使用了sun.misc.Unsafe&#xff0c;比如Netty、Cassandra、Hadoop、Kafka等。Unsafe类在提升Java运行效率&#xff0c;增强Java语言底层操作能力方面起了很大的作用。但Unsafe类在sun.misc包下&#xff0…

Codis 分布式缓存部署

为什么80%的码农都做不了架构师&#xff1f;>>> 环境介绍: 1:机器三台 ,IP/hostname 如下, hostname的设置很重要zookeeper / codis的通信都会用到,所以要配置好三台机器的hosts文件. 10.221.8.220 机器的hostname为 Redis1 10.221.8.221 机器的hostname为 Redis…

treeset java_Java TreeSet Higher()方法与示例

treeset javaTreeSet类Higher()方法 (TreeSet Class higher() method) higher() method is available in java.util package. Higher()方法在java.util包中可用。 higher() method is used to return the lowest element in this TreeSet that is higher than the specified el…

怎么解决MySQL死锁问题的?

咱们使用 MySQL 大概率上都会遇到死锁问题&#xff0c;这实在是个令人非常头痛的问题。本文将会对死锁进行相应介绍&#xff0c;对常见的死锁案例进行相关分析与探讨&#xff0c;以及如何去尽可能避免死锁给出一些建议。话不多说&#xff0c;开整&#xff01;什么是死锁死锁是并…

strictmath_Java StrictMath cos()方法与示例

strictmathStrictMath类cos()方法 (StrictMath Class cos() method) cos() method is available in java.lang package. cos()方法在java.lang包中可用。 cos() method is used to return the trigonometric cosine of an angle of the given parameter in the method. Here, c…

Apache cxf JaxRs基本应用

2019独角兽企业重金招聘Python工程师标准>>> 在前一篇中&#xff0c;我们完成了《Apache cxf JaxWs基本应用》 的编写&#xff0c;我们现在实现一个Restful风格的Cxf 。 一、我们首先依旧是基于Maven project配置pom.xml的依赖 [html] view plaincopyprint? <pr…

白嫖1年阿里云,反手就搭一个Java环境

作者 | 磊哥来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;早上收到阿里云小姐姐的消息&#xff0c;阿里云有搞事情了&#xff0c;这次是送一年的阿里云 ECS 服务器。有便宜不占王八蛋…

setseed_Java Random setSeed()方法与示例

setseed随机类setSeed()方法 (Random Class setSeed() method) setSeed() method is available in java.util package. setSeed()方法在java.util包中可用。 setSeed() method is used to set the given seed of this Random Number Generator. setSeed()方法用于设置此随机数生…

.Net 自己写个简单的 半 ORM (练手)

ORM 大家都知道&#xff0c; .Net 是EF 还有一些其他的ORM 从JAVA 中移植过来的 有 &#xff0c; 大神自己写的也有 不管ORM 提供什么附加的 乱七八糟的功能 但是 最主要的 还是 关系映射 的事情。 我自己一直在使用ORMDapper 这个很小的ORM 第一次看到这个ORM 是通过一…

synchronized和ReentrantLock的5个区别!

作者 | 磊哥来源 | Java面试真题解析&#xff08;ID&#xff1a;aimianshi666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;在 Java 中&#xff0c;常用的锁有两种&#xff1a;synchronized&#xff08;内置锁&#xff09;和 ReentrantLock&a…

Java Random nextInt()方法与示例

随机类nextInt()方法 (Random Class nextInt() method) Syntax: 句法&#xff1a; public int nextInt();public int nextInt(int num);nextInt() method is available in java.util package. nextInt()方法在java.util包中可用。 nextInt() method is used to return the nex…

《小强升职记》读后感和思维导图

语言幽默轻松&#xff0c;寓教于乐&#xff0c;看完之后有挽起袖子大干一场的冲动&#xff0c;但是诚如书中所言&#xff0c;“不做收藏家&#xff0c;要做建筑工”&#xff0c;实践和坚持才能有所收获。第一次画思维导图(′▽〃)Xmind格式文件转载于:https://www.cnblogs.com/…

oppo后端16连问

前言 大家好&#xff0c;我是磊哥。最近有位读者去面试了oppo&#xff0c;给大家整理了面试真题的答案。希望对大家有帮助哈&#xff0c;一起学习&#xff0c;一起进步。聊聊你印象最深刻的项目&#xff0c;或者做了什么优化。你项目提到分布式锁&#xff0c;你们是怎么使用分布…

java enummap_Java EnumMap values()方法与示例

java enummapEnumMap类values()方法 (EnumMap Class values() method) values() method is available in java.util package. values()方法在java.util包中可用。 values() method is used to get all the values in a Collection view of this enum map. values()方法用于获取…