当前位置:网站首页>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.
边栏推荐
- TCP/IP协议
- Purpose of computer F1-F12
- The harm of game unpacking and the importance of resource encryption
- Hutool gracefully parses URL links and obtains parameters
- 可变长参数
- China Light conveyor belt in-depth research and investment strategy report (2022 Edition)
- Unified ordering background interface product description Chinese garbled
- 【MySQL】日志
- 【ROS】usb_ Cam camera calibration
- JS pure function
猜你喜欢
2022.02.13 - NC004. Print number of loops
Using pkgbuild:: find in R language_ Rtools check whether rtools is available and use sys The which function checks whether make exists, installs it if not, and binds R and rtools with the writelines
IOT -- interpreting the four tier architecture of the Internet of things
egg. JS project deployment online server
Swagger setting field required is mandatory
ROS编译 调用第三方动态库(xxx.so)
【ROS】usb_cam相机标定
Detailed explanation of heap sorting
深度剖析C语言指针
Marathon envs project environment configuration (strengthen learning and imitate reference actions)
随机推荐
vb.net 随窗口改变,缩放控件大小以及保持相对位置
View computer devices in LAN
Visual implementation and inspection of visdom
The mysqlbinlog command uses
Pointer advanced --- pointer array, array pointer
sublime text中conda环境中plt.show无法弹出显示图片的问题
2022.02.13 - NC002. sort
Roguelike游戏成破解重灾区,如何破局?
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
Function coritization
Problems in loading and saving pytorch trained models
[MySQL] log
Revit 二次开发 HOF 方式调用transaction
JVM 快速入门
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)
Purpose of computer F1-F12
【MySQL】锁
CISP-PTE实操练习讲解
MySQL learning record 07 index (simple understanding)
Is it safe to open an account in Zheshang futures?