English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Erlang List duplicate Method

Erlang List

Return a list containing the copies of Elem repeated N times.

Syntax

duplicate(N, Elem)

Parameter

  • N −The number of times the element needs to be repeated in the list.

  • Elem −The element that needs to be repeated in the list.

Return Value

Return a new list with the element repeated N times.

-module(helloworld). 
-import(lists,[duplicate/2]). 
-export([start/0]). 
start() -> 
   Lst1 = duplicate(5,1, 
   io:fwrite("~w~n",[Lst1]).

When we run the above program, we will get the following results.

[1,1,1,1,1]

Erlang List