title: AWS S3 Java SDK - ListVersionsRequest Get Only Latest Versions
body: <p>Is there any way to specify to only include the latest version of each object in the <a href="https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/ListVersionsRequest.html" rel="nofollow noreferrer">ListVersionsRequest</a>? I need the version value, so a simple <a href="https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Client.html#listObjects-com.amazonaws.services.s3.model.ListObjectsRequest-" rel="nofollow noreferrer">AmazonS3Client.listObjects(...)</a> will not suffice because <a href="https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/S3ObjectSummary.html" rel="nofollow noreferrer">S3ObjectSummary</a> has no version information.</p>
  
  <p>I am creating a utility that pings S3 for all objects in the versioned bucket and compares the latest version value to what the utility is already tracking. The only solution I can think of right now is just to do <a href="https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Client.html#listVersions-com.amazonaws.services.s3.model.ListVersionsRequest-" rel="nofollow noreferrer">AmazonS3Client.listVersions(...)</a>, iterate through the <a href="https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/S3VersionSummary.html" rel="nofollow noreferrer">S3VersionSummary</a> list, handle the first most recent version then manually iterate and skip all older versions of an objet until it gets to the new key. Is this the best solution?</p>
  
  <p>Thanks</p>