Java Interview Questions (5)

(1) Interview questions:
Is there length() in arrays, length() in strings, and length() in sets?

                数组中没有length()方法,只有length属性
                字符串中有length()
                集合中没有length(),获取集合的元素数:size() 

(2) 面试题:
String s1 = new String("abc");
String s1 = "abc" ;

How many objects do these two create?

==: The comparison is the address value
equals: The default comparison is the address value, the String bottom layer rewrites the equals method, whether all the comparisons are the same
(3) Interview questions:
The difference between StringBuffer and String? The
former is a variable character Sequence, the latter is an immutable sequence of characters.
From the perspective of memory, when String is defined, it will open up space in the constant pool, which consumes more memory
. StringBuffer, string buffer (all stored in it are strings), It will release
(4) Interview question:
What is the difference between StringBuffer and array?

Array: It is a container that can store multiple data, and the types of multiple data must be consistent.
Array length function: length attribute
StringBuffer: It is a container, which always stores only string type data in
the buffer to obtain the buffer. length: length()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324911581&siteId=291194637