1. What is the difference between arraylist, struct list, and vector?
Arraylist is based on the array structure, while list is based on the two-way linked list structure. It can be seen from the operational features of arrays and linked lists that arraylist is faster in search and slower in addition and deletion.
The slow list, on the contrary, is faster when adding or deleting data, and slower when searching.
Like arraylist, vector is stored in an array structure. However, vector uses the synchronized method, which is thread-safe, so it is less efficient than arraylist. If thread security is not required, it is not required.
2. What are the differences between string, stringbuffer, and stringbuilder?
String is a final object, that is, the value cannot be changed. For example, string a = "ABC"; A = a + "D"; the actual process is as follows: first create a stringbuffer sb = new stringbuffer (STR), and then call sb. append (), and then call STR = sb. tostring () is assigned to a new string. Therefore, the string addition and deletion operations are far slower than stringbuffer. When string addition and deletion operations are frequent, there will be a large number of objects in the memory space, increasing the garbage collection overhead.
When using stringbuffer, create an object first, and then change the value of the object stringbuffer sb = new stringbuffer (); sb. append ("ABC ");
The addition and deletion operations of stringbuilder are faster than those of stringbuffer, but it is not thread-safe. Stringbuffer is thread-safe.
So it is so troublesome to add, delete, and delete strings. Isn't it necessary to use stringbuffer all the time? String is applicable when it is called multiple times and rarely modified. In this case, if stringbuffer is used, a new object will be created each time a call is made, and many objects will be allocated in the memory. If the string method is used, no new object is required.