If I had a genie in a bottle, my first wish would be that all programming languages would have the same way of getting length.
| Programming Language | String | Array | Other Common |
|---|---|---|---|
| C |
//using #include <string.h> strlen(char[]) |
//note: sizeof returns size in bytes sizeof(array) / sizeof(datatype or value) |
|
| C++ |
.size() .length() |
//note: sizeof returns size in bytes sizeof(array) / sizeof(datatype or value) |
//Vector .size() |
| C# | .Length |
//returns number of elements in all dimensions .Length //returns number of elements in a specified dimension .GetLength(int dimension) |
//ICollections .Count() |
| Java | .length() | .length |
//ArrayList .size() |
| Python | len(s) | len(s) #note: this is for a python list | |
| JavaScript | .length | .length |