Java Collections copy()方法與示例

集合類的copy()方法 (Collections Class copy() method)

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

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

  • copy() method is used to copy all the elements from List the src_list (source list) and place all the copied elements into List dst_list (destination list).

    copy()方法用于從src_list列表(源列表)中復制所有元素,并將所有復制的元素放入dst_list列表(目標列表)中。

  • copy() method is a static method, so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.

    copy()方法是一個靜態方法,因此可以使用類名進行訪問,如果嘗試使用類對象訪問該方法,則不會收到錯誤。

  • copy() method may throw an exception at the time of copying elements from one list to another.

    將元素從一個列表復制到另一個列表時, copy()方法可能會引發異常。

    • IndexOutOfBoundsException: This exception may throw when the given parameter dst_list size is lesser than the src_list.
    • IndexOutOfBoundsException :當給定參數dst_list的大小小于src_list時,可能引發此異常。
    • UnsupportedOperationException: This exception may throw when the given parameter dst_list un-support set operation.
    • UnsupportedOperationException :如果給定參數dst_list不支持set操作,則可能引發此異常。

Syntax:

句法:

    public static void copy(List dst_list, List src_list);

Parameter(s):

參數:

  • List dst_list – represents the destination list.

    列表dst_list –表示目標列表。

  • List src_list – represents the source list.

    列表src_list –表示源列表。

Return value:

返回值:

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

此方法的返回類型為void ,不返回任何內容。

Example:

例:

// Java program is to demonstrate the example of
// void copy() method of Collections 
import java.util.*;
public class Copy {
public static void main(String args[]) {
// Instantiate two LinkedList object
List < Integer > src_l = new LinkedList < Integer > ();
List < Integer > dest_l = new LinkedList < Integer > ();
// By using add() method is to add
// few elements in src_l
src_l.add(10);
src_l.add(20);
src_l.add(30);
src_l.add(40);
// By using add() method is to add
// few elements in dest_l
dest_l.add(60);
dest_l.add(70);
dest_l.add(80);
dest_l.add(90);
// Display LinkedList
System.out.println("src_l: " + src_l);
System.out.println("dest_l: " + dest_l);
// By using copy() method is to
// copy the elements of src_l into a dest_l
Collections.copy(dest_l, src_l);
System.out.println();
// Display Copied LinkedList
System.out.println("Collections.copy(dest_l, src_l): " + dest_l);
}
}

Output

輸出量

src_l: [10, 20, 30, 40]
dest_l: [60, 70, 80, 90]Collections.copy(dest_l, src_l): [10, 20, 30, 40]

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

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

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

相關文章

c#如何實現叫號操作_微信預約排隊叫號系統操作指南

“微信排隊預約"功能是阿拉善盟稅務局為進一步優化營商環境&#xff0c;深化“放管服”改革&#xff0c;提高納稅便利度&#xff0c;更好地服務于阿拉善經濟社會發展而開發的一項便民措施。通過“微信排隊預約”功能&#xff0c;納稅人可以隨時隨地通過微信獲取辦稅大廳的…

計算機用戶越權操作的原因,“三員系統”中常見的越權問題

原標題&#xff1a;“三員系統”中常見的越權問題一、越權訪問越權訪問(Broken Access Control&#xff0c;簡稱BAC)是Web應用程序中一種常見的漏洞&#xff0c;由于其存在范圍廣、危害大&#xff0c;被OWASP列為Web應用十大安全隱患的第二名。1.1越權訪問的產生比如&#xff0…

富士施樂2022網絡掃描設置_富士施樂(FUJI XEROX)全系列復印機產品介紹

富士施樂(FUJI XEROX)復印機全系列詳解富士施樂復印機是中小型辦公環境的理想機型。所有的都擁有高效生產力和強大的穩定性&#xff0c;無論您需要亮麗色彩、黑白打印、亦或是足以應對復雜文檔工作流的強大功能&#xff0c;總有一款適合您。DocuCentre S2110NDocuCentre S2110N…

ruby hash方法_Ruby中帶有示例的Hash.rassoc(obj)方法

ruby hash方法Hash.rassoc(obj)方法 (Hash.rassoc(obj) Method) In this article, we will study about Hash.rassoc(obj) Method. The working of the method can’t be assumed because of it’s quite a different name. Let us read its definition and understand its imp…

JavaMail(四):接收郵件

2019獨角獸企業重金招聘Python工程師標準>>> 接收郵件采用POP3協議進行接收&#xff0c;簡單的一個接收郵件案例如下 /*** 接收郵件*/ public static void receive() throws Exception { // 準備連接服務器的會話信息 Properties props new Properties(); props.se…

html流動海報css,海報網css代碼怎樣把模塊移到右面?最好把代碼直接給我!嘿嘿。...

匿名用戶13級2010-09-15 回答CSS是Cascading style Sheets的簡稱&#xff0c;中文譯作“層疊樣式表單”. 實際上它是一組樣式。你可能對CSS這個名詞比較陌生&#xff0c;實際上無論你用Internet Explorer還是Netscape Navigator在網上沖浪&#xff0c;幾乎隨時都在與CSS打交道&…

奧鵬東北大學作業答案計算機網絡,東北大學17秋學期《計算機網絡》在線作業1參考答案...

一、單選題:【15道,總分:75分】東北大學1.IP地址0.0.0.0表示( )。 (滿分:5)A. 廣播B. 有限廣播C. 自環地址D. 本機2.IP協議中&#xff0c;如果首部不含選項字段&#xff0c;則首部長度字段的值應為( )。 (滿分:5)A. 0B. 5C. 10D. 203.滑動窗口的作用是…

append生成新變量的時候,沒有如預期(It's a feature,not a bug?)

這是我在寫一個項目中&#xff0c;遇到的一個golang的feature&#xff0c;如代碼所示&#xff0c;我在for循環里&#xff0c;每次用append生成一個新的數組&#xff0c;&#xff08;當然我以前一直以為可以這樣&#xff0c;直到我在stackoverflow上發現不能。&#xff09;然后將…

jqgrid本地數據例子_辦公系統私有云公有云和本地化部署,你選哪個?

隨著互聯網和云計算技術的發展&#xff0c;我們常常會聽到&#xff1a;私有云、公有云和本地化部署&#xff0c;它們分別代表什么意思&#xff1f;無論是國企、民企還是外企&#xff0c;只要有數據&#xff0c;就要思考&#xff1a;到底將數據儲存在哪里&#xff1f;選擇輕流進…

計算機基礎應用的培養活動記錄,小學少年宮計算機興趣小組活動記錄表

小學少年宮計算機興趣小組活動記錄表 小學少年宮計算機興趣小組活動記錄表 活動名稱&#xff1a;計算機 指導教師&#xff1a; ⅩⅩ 學生姓名 活動地點 計算機教室 活 動 過 程 活動1&#xff0e;認識計算機 ①師&#xff1a;“請同學們按下方盒子上面像大鈕扣一樣的按鈕&#…

C ++ STL中的set :: lower_bound()函數

C STL set :: lower_bound()函數 (C STL set::lower_bound() function) set::lower_bound() function is a predefined function, it is used to get the lower bound of any element in a set. set :: lower_bound()函數是預定義的函數&#xff0c;用于獲取集合中任何元素的下…

flume入門

# example.conf: A single-node Flume configuration# Name the components on this agent #給那三個組件取個名字 a1.sources r1 a1.sinks k1 a1.channels c1# Describe/configure the source #類型, 從網絡端口接收數據,在本機啟動, 所以localhost, typespoolDir采集目錄源…

原生js設置div隱藏或者顯示_JavaScript動畫方式控制div元素的隱藏和顯示

jQuery實現此功能相對比較簡單&#xff0c;具體參閱點擊按鈕動畫方式隱藏和顯示div一章節。結合CSS3實現此功能也非常便利和適合&#xff0c;具體參閱JavaScript與CSS3動畫方式改變元素尺寸一章節。原生JavaScript實現稍顯麻煩&#xff0c;下面就通過代碼實例介紹一下如何實現此…

python線程任務run_Python線程類| 帶有示例的run()方法

python線程任務runPython Thread.run()方法 (Python Thread.run() Method) Thread.run() method is an inbuilt method of the Thread class of the threading module in Python. This method is used to represent a threads activity. It calls the method expressed as the …

哪個計算機無法做到雙屏顯示,怎么啟用雙屏顯示設置【圖文介紹】

隨著生活質量的提升&#xff0c;人們對于便利的要求越來越高&#xff0c;電腦的雙屏顯示成為現在用戶越來越關注的對象之一。比如炒股操作中&#xff0c;人們既要關注大盤的走動趨勢&#xff0c;又要關注特定股票的走勢&#xff0c;在普通的屏幕上就需要不斷地切換頁面&#xf…

1.django 開發環境搭建

2019獨角獸企業重金招聘Python工程師標準>>> 本教程使用的開發環境 本教程寫作時開發環境的系統平臺為 Windows 10 &#xff08;64 位&#xff09;&#xff0c;Python 版本為 3.5.2 &#xff08;64 位&#xff09;&#xff0c;Django 版本為 1.10.6。 建議盡可能地與…

改jpg_|我來改第04期|—人物海報設計

【我來改第04期】人物海報文案內容-Ad copyhttps://pan.baidu.com/s/16pz9_rcLXTGZ3xzKFjKN9g 密碼: r57t設計要求-Requirement尺寸&#xff1a;1080(高)*650(寬)像素&#xff0c;大小不大于5m設計要求&#xff1a;以目前的藍色為主要顏色(R:47,G:87,B:130)&#xff0c;畫面體…

Java即時類| plus()方法與示例

即時類plus()方法 (Instant Class plus() method) Syntax: 句法&#xff1a; public Instant plus(TemporalAmount t_amt);public Instant plus(long amt, TemporalUnit t_unit);plus() method is available in java.time package. plus()方法在java.time包中可用。 plus(Temp…

計算機領域中dns是什么意思,dns錯誤是什么意思?dns錯誤要如何解決?

隨著網絡的普及&#xff0c;電腦已經成為我們生活中必不可少的物品&#xff0c;它可以幫助我們工作和學習以及娛樂。不過電腦在使用的過程中&#xff0c;常常會出現一些問題&#xff0c;小編覺得最常見也最讓人心生煩躁的就是輸入網址打開之后出現網頁打不開&#xff0c;提示dn…

Launch Instruments

Launch Instruments 該儀器應用在Xcode應用程序&#xff0c;所以推出是在Xcode的最直接的方式。你也可以啟動它間接地通過碼頭&#xff0c;啟動&#xff0c;或命令行。The Instruments app lives inside the Xcode app, so the most direct way to launch it is from within Xc…