Q:

How to get versioning information of a s3 object?

I need to get versioning information of objects. Forexample i have an object key and a bucket name and with this information i can get his version id via getObject method. But what i need is to know how many version has that object.
getObject(bucketName, key).getObjectMetadata().getVersionId()

Forexample this method listVersions
 public VersionListing listVersions(String bucketName, String prefix) throws SdkClientException, AmazonServiceException {
        return this.listVersions(new ListVersionsRequest(bucketName, prefix, (String)null, (String)null, (String)null, (Integer)null));
    }

How should i use here bucket name and key to retrieve versioning information of an object?

A:

Here is the code which i found to get versioning information.
ListVersionsRequest request = new ListVersionsRequest()
                            .withBucketName(bucketName)
                            .withPrefix(bucketKey);

VersionListing versionListing = s3Service.listVersions(request);

List<S3VersionSummary> versionSummaries = versionListing.getVersionSummaries();

