发布网友 发布时间:2022-04-23 12:40
共9个回答
热心网友 时间:2022-04-24 01:34
是求字符串长度的一个方法
如:String str = "abcdefg";
int i =str.length();
算出来i等于7
对于数组或集合,length是属性
如:int[] array = {1,2,3,4,5,6};
int i = array.length ;//求数组的长度
算出来i等于6
热心网友 时间:2022-04-24 02:52
length属性是针对Java中的数组来说的,要求数组的长度可以用其length属性;
public static void main(String[] args) ;
String []list={"ma","cao","yuan"};
System.out.println(list.length);
List
Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。
热心网友 时间:2022-04-24 04:26
是方法,你可去看下源代码
/**
* Returns the length of this string.
* The length is equal to the number of <a href="Character.html#unicode">Unicode
* code units</a> in the string.
*
* @return the length of the sequence of characters represented by this
* object.
*/
public int length() {
return count;
}追问public class TestString
{
public static void main(String[] args)
{
String s = "Mary,F,1976";
String[] sPlit = s.split(",");
for(int i = 0; i < sPlit.length; i++)
System.out.println(sPlit[i]);
}
}
为什么没有报错?
热心网友 时间:2022-04-24 06:18
length属性是针对Java中的数组来说的,要求数组的长度可以用其length属性;
public static void main(String[] args) {
String []list={"ma","cao","yuan"};
System.out.println(list.length);
List
}
热心网友 时间:2022-04-24 08:26
类的length一般是方法。数组的length才是属性
热心网友 时间:2022-04-24 10:50
方法,Str.length()
热心网友 时间:2022-04-24 13:32
Str.length
热心网友 时间:2022-04-24 16:30
是方法
热心网友 时间:2022-04-24 19:44
方法