字符串与数组集合的长度获取

字符串、数组、集合

类型 长度获取的方法 示例 字符串String length()
 String str = "abc"
 int length = str.length();
 System.out.println(length);//3
数组Array length
int[] arr = new int[]{1,2,3,4,5};
int length = arr.length;
System.out.println(length);//5
list集合 size()
ArrayList<Integer> list = new ArrayList<>();
        int size = list.size();
        System.out.println(size);//0
HashSet、HashMap集合 size()
HashSet<String> hashSet = new HashSet<>();
int size = hashSet.size();


 

猜你喜欢

转载自blog.csdn.net/weixin_43912118/article/details/85221430
今日推荐