Creating a list with repeating element

You can use Collections.nCopies. Note that this copies the reference to the given object, not the object itself. If you’re working with strings, it won’t matter because they’re immutable anyway.

List<String> list = Collections.nCopies(5, "foo");
System.out.println(list);
[foo, foo, foo, foo, foo]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)