java中的length
2024-02-15 17:12:02
對(duì)于個(gè)數(shù)組來(lái)說(shuō),`length`屬性返回的是數(shù)組元素的個(gè)數(shù)。:
```java
int[] array = new int[];
System.out.println(array.length); // 輸出 ""
```
對(duì)于個(gè)字符串來(lái)說(shuō),`length()`方法返回的是字符串中的字符個(gè)數(shù)。:
```java
String str = "Hello";
System.out.println(str.length()); // 輸出 ""
```