The first thing that I would do in any scenario like this is to use the of() method but for some reason it doesn't work. I copied the exact same code into eclipse and it worked just fine so I don't know why codegym is doing this. I downloaded the correct code and it showed me like the HashSet but there where so many add()'s. I would think that my approach would be more efficient so why won't it work?
package com.codegym.task.task08.task0813;
import java.util.Set;
import java.util.HashSet;
/*
20 words that start with the letter "L"
*/
public class Solution {
public static Set<String> createSet() {
Set<String> set = Set.of("Long", "La", "Lb", "Lc", "Ld", "Le", "Lf", "Lg", "Lh", "Li", "Lj", "Lk", "Ll,",
"Lm", "Ln", "Lo", "Lp", "Lq", "Lr", "Ls");
return set;
}
public static void main(String[] args) {
}
}