This language bar is your friend. Select your favorite languages!

Idiom #44 Insert element in list

Insert element x at position i in list s. Further elements must be shifted to the right.

s.insert (s.begin () + i, x);
import std.array;
s.insertInPlace(i, x);
s.insert(i, x);
List.insert_at(s, i, x)
{Left, Right} = lists:split(I-1, S),
Left ++ [X|Right].
s = append(s, 0)
copy(s[i+1:], s[i:])
s[i] = x
take i s ++ x : drop i s
s.splice(i, 0, x);
import java.util.List;
s.add(i, x);
array_splice($s, $i, 0, $x);
Uses Classes;
s.Insert(i, x)
splice(@s, $i, 0, $x)
s.insert(i, x)
s.insert(i, x)
s.insert(i, x);

Do you know the best way to do this in your language ?
New implementation...

Idiom created by


Related idioms