This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
- C++
- C#
- D
- Dart
- Elixir
- Erlang
- Fortran
- Go
- Go
- Haskell
- JS
- Java
- Java
- Java
- Kotlin
- Lisp
- Lua
- PHP
- Pascal
- Perl
- Python
- Ruby
- Rust
- VB
int a = 0, n = s.length;
Class<?> c = s.getClass().getComponentType();
T t[] = (T[]) newInstance(c, n + 1);
arraycopy(s, a, t, a, i);
t[i] = x;
arraycopy(s, i, t, i + 1, n - i);
int a = 0, n = s.length,
t[] = new int[n + 1];
arraycopy(s, a, t, a, i);
t[i] = x;
arraycopy(s, i, t, i + 1, n - i);
splice(@s, $i, 0, $x);
The 0 tells splice we're replacing zero elements with $x at position $i, resulting in an insertion rather than replacement. The problem does not specify if the position i is 0 or 1 based - so be careful when implementing in real code.