当前位置:网站首页>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.
边栏推荐
- Generator parameters incoming parameters
- Unified ordering background interface product description Chinese garbled
- China high purity silver nitrate Market Research and investment strategy report (2022 Edition)
- LDAP application (4) Jenkins access
- 有效提高软件产品质量,就找第三方软件测评机构
- 可变长参数
- sublime text中conda环境中plt.show无法弹出显示图片的问题
- hutool优雅解析URL链接并获取参数
- Purpose of computer F1-F12
- 如何有效地进行自动化测试?
猜你喜欢
ROS compilation calls the third-party dynamic library (xxx.so)
可变长参数
Restful API design specification
软件卸载时遇到trying to use is on a network resource that is unavailable
sublime text中conda环境中plt.show无法弹出显示图片的问题
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
vb.net 随窗口改变,缩放控件大小以及保持相对位置
ROS编译 调用第三方动态库(xxx.so)
Sort according to a number in a string in a column of CSV file
Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures
随机推荐
ESP8266-RTOS物联网开发
Marathon envs project environment configuration (strengthen learning and imitate reference actions)
Indentation of tabs and spaces when writing programs for sublime text
MySQL learning record 07 index (simple understanding)
MySQL learning record 11jdbcstatement object, SQL injection problem and Preparedstatement object
[MySQL] lock
Research Report on supply and demand and development prospects of China's high purity aluminum market (2022 Edition)
Cisp-pte practice explanation
visdom可视化实现与检查介绍
R language uses the principal function of psych package to perform principal component analysis on the specified data set. PCA performs data dimensionality reduction (input as correlation matrix), cus
优秀的软件测试人员,都具备这些能力
Introduction to the differences between compiler options of GCC dynamic library FPIC and FPIC
ROS编译 调用第三方动态库(xxx.so)
[NVIDIA development board] FAQ (updated from time to time)
企微服务商平台收费接口对接教程
JVM performance tuning and practical basic theory - Part 1
sys. argv
PC easy to use essential software (used)
查看局域网中电脑设备
Deep learning: derivation of shallow neural networks and deep neural networks