I have the following listing in groovy
public enum ImageTypes {
jpg ("image/jpeg"),
jpeg ("image/jpeg"),
jpe ("image/jpeg"),
jfif ("image/jpeg"),
bmp ("image/bmp"),
png ("image/png"),
gif ("image/gif"),
ief ("image/ief"),
tiff ("image/tiff"),
tif ("image/tiff"),
pcx ("image/pcx"),
pdf ("application/pdf"),
final String value
ImageTypes(String value) {
this.value = value
}
String getValue() {
return this.value
}
String toString(){
value
}
String getKey() {
name()
}
}
and I want to create an ArrayList <String> of keys or values
What I'm doing now is iterating over all the elements and creating a list of arrays, but I think there should be an easy way to do this ...
def imageTypes = ImageTypes.values()
def fileExts = new ArrayList<String>()
def mimeTypes = new ArrayList<String>()
for (type in imageTypes) {
fileExts.add(type.key)
mimeTypes.add(type.value)
}
source
share