当前位置:网站首页>Unsupported operation exception
Unsupported operation exception
2022-07-06 08:42:00 【Mr. Liangliang on the top of the head】
Let's review the topic first , If you have any questions, you can move the portal .String[] and List< String > Differences and mutual transformation of
public class test {
public static void main(String[] args) {
// Define a character length of 5 String
String[] strings = new String[5];
strings[0] = "a";
strings[1] = "b";
strings[2] = "c";
strings[3] = "d";
strings[4] = "e";
// call Arrays Medium asList Methods will String[] Turn into List<String>
List<String> list = Arrays.asList(strings);
System.out.println("list<String>:"+list.toString());
// by list Add an element
list.add("f");
System.out.println("list<String>:"+list.toString());
}
}
Dangdang when , Are the little ones the same as I thought , It's no problem , Isn't that great , First the String[] Convert to List< String >, Then add another element f, The final output is a,b,c,d,e,f.
This logic is perfect , Here with Zulan perfect.
Ha ha ha , Still too young , If so , What else did I say , There's nothing more to say ( Stand hand ).
Okay , Don't talk much , Let's see the result directly .
duang, Silly eyes , Why , What is this , Why did you make a mistake , This is illogical . Have I changed my dish again ,nonono, I want to be a big bird's female paper .
Now let's start the formal explanation , Stop it .
- Let's see first and then String[] To List< String > There is no error reported when , Is the correct output of the results . That's right List Conduct add During operation , Wrong report .emmm, In which line did you make a mistake and found .
- Now let's look , Why did he report an error . Let's take a look at the transformation , What did you do , Here's the picture ,asList By creating a new ArrayList To receive String[] The numerical .
- Look again ArrayList Is it the one we are familiar with ArrayList, That is to say, you can go through add,remove Method to operate , Here's the picture , Obviously , This is not ArrayList class , It is Arrays There is a new internal class ArrayList, This inner class inherits from AbstractList class ,AbstractList The inside of the class add The method is to throw UnsupportedOperationException Anomalous .
- Then someone wants to ask , Why , What then? ArrayList Yes. , The answer is ArrayList Have done something for us , That is to rewrite add Method .
To sum up , If in the future String[] Turn into List< String > When , It is impossible to add,remove Operation of the , Because they are not familiar to us ArrayList, It is Arrays Inner class in ArrayList.
边栏推荐
- [2022 Guangdong saim] Lagrange interpolation (multivariate function extreme value divide and conquer NTT)
- Deep anatomy of C language -- C language keywords
- egg. JS directory structure
- 704 binary search
- Deep analysis of C language pointer
- China Light conveyor belt in-depth research and investment strategy report (2022 Edition)
- On the inverse order problem of 01 knapsack problem in one-dimensional state
- Image,cv2读取图片的numpy数组的转换和尺寸resize变化
- pytorch训练好的模型在加载和保存过程中的问题
- 2022.02.13 - 238. Maximum number of "balloons"
猜你喜欢
被破解毁掉的国产游戏之光
Double pointeur en langage C - - modèle classique
堆排序详解
[cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes
Deep analysis of C language data storage in memory
marathon-envs项目环境配置(强化学习模仿参考动作)
优秀的软件测试人员,都具备这些能力
Sort according to a number in a string in a column of CSV file
Leetcode question brushing (5.28) hash table
可变长参数
随机推荐
egg. JS project deployment online server
Colorlog combined with logging to print colored logs
The harm of game unpacking and the importance of resource encryption
JVM performance tuning and practical basic theory - Part 1
Image,cv2读取图片的numpy数组的转换和尺寸resize变化
Detailed explanation of heap sorting
VMware virtualization cluster
Sort according to a number in a string in a column of CSV file
查看局域网中电脑设备
logback1.3. X configuration details and Practice
R language ggplot2 visualization: place the title of the visualization image in the upper left corner of the image (customize Title position in top left of ggplot2 graph)
Roguelike游戏成破解重灾区,如何破局?
Verrouillage [MySQL]
Image, CV2 read the conversion and size resize change of numpy array of pictures
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Purpose of computer F1-F12
Process of obtaining the electronic version of academic qualifications of xuexin.com
软件压力测试常见流程有哪些?专业出具软件测试报告公司分享
【ROS】usb_cam相机标定
有效提高软件产品质量,就找第三方软件测评机构