0
How can we change the first index of an array to 1? Pls tell
I'm asking coz it's very inconvenient for 0 to be the first
4 Answers
+ 1
There is only a limited amount of languages that use 1 and not 0, I can name Lua and MatLab. It is not a very smart choice, because when it comes to using minuses, then 0 is a neutral number, hence why we start with it.
If you still want to somehow change it, the best you can do is make a custom class in whatever language you are using that takes care of array handling, like a List and start from 1.
0
Sorry it is for java
0
If you are using a OOP language you can create you special array class that extends the built-in array class.
If you don't like OOP, there are workarounds depending on the language. For example you can create an associative array whose first key is 1.
It is worth mentioning that in some languages like Lua arrays start at 1 by default.