List with all item names

Jan 19, 2021
List with all item names
  • For < Java 1.8:
    Code (Java):
    List<String> materialNames = new ArrayList<>();

    for (Material material : Material.values())
        names.add(material.name());
    Java 1.8+ with streams:
    Code (Java):
    List<String> materialNames = Arrays.stream(Material.values())
            .map(Material::name)
            .collect(Collectors.toList());
  • Loading...
  • Loading...