Logo

Programming-Idioms

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

Idiom #332 List of the keys of a map

Create the list k containing all the keys of the map m

fgl
type
  TList = specialize TFPGList<TKey>;
  TMap = specialize TFPGMap<TKey, TData>;

var
  m: TMap;
  k: TList;

begin
  ....
  k := TList.Create;
  for idx := 0 to m.Count-1 do k.Add(m.Keys[idx]);
  .....
  k.Free;
  ....

TKey and TData can be of any type except a class.
final k = m.keys;

The order of the element depends on the Map implementation

New implementation...
< >
programming-idioms.org