I'm trying to create & populate Shapefile in Java using GeoTools.

Basically following this link (quite similar to the official documentation & other tutorials specifically for the point I'm asking below).

For below code I'm getting first warning that FeatureCollections is deprecated and error that add() cannot be resolved.

FeatureCollection<SimpleFeatureType, SimpleFeature> collection = FeatureCollections.newCollection();

How can I fix that or any other way to create Shapefile using Java?

1 Answer 1


The prefered solution is to use the gt-csv datastore to read in the features which will return you a feature collection directly, that you can then write out to a shapefile.

If you really need to do your own parsing the simplest solution is to put the features into a Java collection (e.g. list) and then call DataUtilities.collection(list) on it.

Or you could use DefaultFeatureCollection

SimpleFeatureType featureType = DataUtilities.createType(tipoShape,
      "the_geom:" + tipoShape + ":srid=4326," + "number:Integer");

DefaultFeatureCollection featureCollection = new DefaultFeatureCollection("internal", featureType);

But make sure to call you geometry column the_geom or the Shapefile writer will ignore it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.