C#:

 1 public class demo01
 2     {
 3         public void test01()
 4         {
 5             //数组的长度是.Length
 6             int[] ary = new int[] { 1, 2, 3 };
 7             Console.WriteLine(ary.Length);
 8 
 9             //字符串的长度是.Length
10             string str = "abc";
11             Console.WriteLine(str.Length);
12 
13             //List的长度是.Count
14             List<int> list = new List<int>();
15             Console.WriteLine(list.Count);
16 
17             //Set的长度是.Count
18             HashSet<string> set = new HashSet<string>();
19             Console.WriteLine(set.Count);
20 
21             //Dictionary的长度是.Count
22             Dictionary<string, int> dic = new Dictionary<string, int>();
23             Console.WriteLine(dic.Count);
24         }
25     }

 

Java:

 1 public class demo01 {
 2     public static void main(String[] args) {
 3         //数组的长度是.length
 4         int[] ary = new int[] {1,2,3};        
 5         System.out.println(ary.length);
 6         
 7         //字符串的长度是.length()
 8         String str = "abc";
 9         System.out.println(str.length());
10         
11         //List的长度是.size()
12         List<Integer> list = new ArrayList<Integer>();
13         System.out.println(list.size());
14         
15         //Set的长度是.size()
16         Set<String> set = new HashSet<>();
17         System.out.println(set.size());
18         
19         //Map的长度是.size()
20         Map<String, Integer> map = new HashMap<String, Integer>();
21         System.out.println(map.size());
22     }
23 }

 

posted on 2021-10-22 08:52  Sempron2800+  阅读(32)  评论(0编辑  收藏  举报