Search code examples
javac#listarraylistcode-translation

How to translate this List to Java?


I am currently getting an error requesting that certain identifiers are expected as I try to translate this C# code:

public static List<string> stopWords = new List<string> {"ON","OF","THE","AN","A" };

current faulty Java code:

public static List<String> stopWords = new ArrayList<String {"ON","OF","THE","AN","A" };

Solution

  • You could use

    List<String> stopWords = new ArrayList<>(Arrays.asList("ON","OF","THE","AN","A" ));