数组求长度用length属性
字符串求长度用length()方法
集合求长度用size()方法
程序举例:
package 集合.length_size; import java.util.ArrayList; import java.util.List; public class Length_Size { public static void main(String[] args) { String[] strings = {"aaa","bbb","ccc"}; String string = "aaabbbccc"; List<Integer> list = new ArrayList<Integer>(); list.add(1); System.out.println("String[].length="+strings.length); System.out.println("String.length()="+string.length()); System.out.println("List.size()="+list.size()); } }
时间: 2024-10-25 18:48:43