set vector_Java Vector set()方法與示例

set vector

向量類set()方法 (Vector Class set() method)

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

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

  • set() method is used to replace the old element with the given element (ele) when it exists otherwise it sets the given element at the given indices in this Vector.

    set()方法用于在給定元素(ele)存在的情況下將其替換為給定元素(ele),否則它將在給定Vector的給定索引處設置給定元素。

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

    set()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • set() method may throw an exception at the time of replacing the element.

    set()方法在替換元素時可能會引發異常。

    ArrayIndexOutOfBoundsException: This exception may throw when the given first parameter is not in a range.

    ArrayIndexOutOfBoundsException :如果給定的第一個參數不在范圍內,則可能引發此異常。

Syntax:

句法:

    public Element set(int indices, Element ele);

Parameter(s):

參數:

  • int indices – represents the indices of replacing element.

    int index –表示替換元素的索引。

  • Element ele – represents the element to be set at the given indices.

    元素ele –表示要在給定索引處設置的元素。

Return value:

返回值:

The return type of the method is Element, it returns the old element at the given indices when exists.

方法的返回類型為Element ,如果存在,它將在給定索引處返回舊元素。

Example:

例:

// Java program to demonstrate the example 
// of Element set(int indices, Element ele) method 
// of Vector 
import java.util.*;
public class SetOfVector {
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
System.out.println("v: " + v);
// By using set() method is to
// replace the element JAVA at the 
// indices 2 with the given element
// SFDC
v.set(2, "SFDC");
// Display updated vector
System.out.println("v.set(2, SFDC): " + v);
}
}

Output

輸出量

v: [C, C++, JAVA]
v.set(2, SFDC): [C, C++, SFDC]

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

set vector

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377796.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377796.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377796.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Android PreferenceActivity 使用

我想大家對于android的系統配置界面應該不會陌生吧&#xff0c;即便陌生&#xff0c;那么下面的界面應該似曾相識吧&#xff0c;假若還是不認識&#xff0c;那么也沒有關系&#xff0c;我們這一節主要就是介紹并講解android 中系統配置界面的使用&#xff0c;相信大家看完本節后…

Pandas(數據分析處理庫)---講解

本內容來自《跟著迪哥學Python數據分析與機器學習實戰》&#xff0c;該篇博客將其內容進行了整理&#xff0c;加上了自己的理解&#xff0c;所做小筆記。若有侵權&#xff0c;聯系立刪。 迪哥說以下的許多函數方法都不用死記硬背&#xff0c;多查API多看文檔&#xff0c;確實&a…

hdu 1141

地址&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid1141 題意&#xff1a;atmel公司1960年發布4bits的處理器&#xff0c;每10年翻一番。給一個年份&#xff0c;問最近一次發布的處理器能運算的n!最大的n是多少。 mark&#xff1a;最大的處理器位數是2160年的4194304…

leetcode 78. 子集 思考分析

題目 給定一組不含重復元素的整數數組 nums&#xff0c;返回該數組所有可能的子集&#xff08;冪集&#xff09;。 說明&#xff1a;解集不能包含重復的子集。 思考分析 畫出解空間樹。 我們可以發現我們所需要的結果是解空間的所有結點。而我們之前組合問題和分割問題都是…

PHP checkdate()函數與示例

PHP checkdate()函數 (PHP checkdate() function) checkdate() function is used to check the valid Gregorian dates. It accepts the date and returns Boolean values (True/False) based on the date values. checkdate()函數用于檢查有效的公歷日期。 它接受日期&#xf…

設計模式讀書筆記-----備忘錄模式

個人比較喜歡玩單機游戲&#xff0c;什么仙劍、古劍、鬼泣、使命召喚、三國無雙等等一系列的游戲我都玩過(現在期待凡人修仙傳)&#xff0c;對于這些游戲除了劇情好、場面大、爽快之外&#xff0c;還可以隨時存檔&#xff0c;等到下次想玩了又可以從剛開始的位置玩起(貌似現在的…

【C++grammar】vector類和字符串字面量

C的vector類 用數組存放數據時&#xff0c;容量大小不可變&#xff0c;vector對象容量可自動增大。 vector的操作&#xff1a; 調用push_back函數時&#xff0c;vector對象的容量可能會增大。 觀察下列操作對vector的影響&#xff1a; #include <vector> #include <…

除去數組中的空字符元素array_filter

<?php$str1_arrayarray(電影,,http://www,,1654,);$str1_arrayarray_filter($str1_array);print_r($str1_array); ?>顯示結果&#xff1a;Array( [0] > 電影 [2] > http://www [4] > 1654) 轉載于:https://www.cnblogs.com/skillCoding/archive/20…

date.after方法_Java Date after()方法與示例

date.after方法日期類after()方法 (Date Class after() method) after() method is available in java.util package. after()方法在java.util包中可用。 after() method is used to check whether this date is after the given date (d) or not. after()方法用于檢查此日期是…

Matplotlib(數據可視化庫)---講解

本內容來自《跟著迪哥學Python數據分析與機器學習實戰》&#xff0c;該篇博客將其內容進行了整理&#xff0c;加上了自己的理解&#xff0c;所做小筆記。若有侵權&#xff0c;聯系立刪。 迪哥說以下的許多函數方法都不用死記硬背&#xff0c;多查API多看文檔&#xff0c;確實&a…

找min和max

看到的貌似是阿里的筆試題&#xff0c;題意是一組數&#xff0c;要找到min和max&#xff0c;同時要求時間復雜度&#xff08;比較次數&#xff09;小于2n&#xff08;2n的辦法都想得到&#xff09;。 別人的思路&#xff1a;n個數的數組里看作每兩個一組&#xff0c;若n是奇數&…

Shader Compiler 界面進展1

先從模仿Composer的界面開始. 目前的進展:不用不知道,雖然wxweidgets有很多界面工具如DialogBlocks(DB), 但仍然不好使. 我使用wxAui界面, DialogBlocks并不支持輸出其xrc格式, 我猜是wx本身就沒有解析wxAui的xrc格式.像wxAuiToolBar或其他wxToolBar, DB工具也不能獨立輸出xrc.…

leetcode 90. 子集 II 思考分析

與本題相關聯的題目解析&#xff1a; leetcode 78. 子集 思考分析 leetcode 40. 組合總和 II思考分析 題目 給定一個可能包含重復元素的整數數組 nums&#xff0c;返回該數組所有可能的子集&#xff08;冪集&#xff09;。 說明&#xff1a;解集不能包含重復的子集。 思考 …

java bitset_Java BitSet and()方法與示例

java bitsetBitSet類和()方法 (BitSet Class and() method) and() method is available in java.util package. and()方法在java.util包中可用。 and() method is used to perform logical AND between two Bitset. This bit set is updated so that every bit holds the value…

Redis-主從復制

一、Redis的Replication&#xff1a; 這里首先需要說明的是&#xff0c;在Redis中配置Master-Slave模式真是太簡單了。相信在閱讀完這篇Blog之后你也可以輕松做到。這里我們還是先列出一些理論性的知識&#xff0c;后面給出實際操作的案例。 下面的列表清楚的解釋了Redis…

.wav音樂文件轉換為.fft.npy頻譜格式文件

需要修改的地方 十個文件夾&#xff0c;每個文件夾下都有100首.au格式的音樂&#xff0c;這里舉個例子&#xff0c;那其中5個類別進行轉換 genre_list ["classical", "jazz", "country", "pop", "rock", "metal"…

WINDOWS編程筆記 2012.2.7

操作系統感知事件和傳遞事件是通過消息機制來實現的typedef struct tagMSG{ HWND hwnd; //窗口的句柄 UINT message; WPARAM wParam; //信息的附加參數 LPARAM lParam; DWORD time; //消息傳遞的時間 POINT pt; //消息投遞的時候&#xff0c;光標的位置}…

php 郵件驗證_PHP程序來驗證電子郵件地址

php 郵件驗證Suppose there is a form floating where every user has to fill his/her email ID. It might happen that due to typing error or any other problem user doesnt fill his/her mail ID correctly. Then at that point, the program should be such that it sho…

【C++grammar】結構化綁定

目錄定義1、用于原生數組的結構化綁定聲明2、用于std::array的結構化綁定聲明3、用于對象數據成員的結構化綁定聲明定義 結構化綁定聲明是一個聲明語句&#xff0c;意味著聲明了一些標識符并對標識符做了初始化。將指定的一些名字綁定到初始化器的子對象或者元素上。 對于初始…

URAL 1106 Two Teams (DFS)

題意 小組里有N個人&#xff0c;每個人都有一個或多個朋友在小組里。將小組分成兩個隊伍&#xff0c;每個隊伍的任意一個成員都有至少一個朋友在另一個隊伍。 思路 一開始覺得和前幾天做過的一道2-sat&#xff08;每個隊伍任意兩個成員都必須互相認識&#xff09;相似然后就往那…