---
title: "Compare"
description: "Compare"
url: "https://www.contentstack.com/docs/developers/sdks/content-management-sdk/java/reference/compare"
product: "Contentstack"
doc_type: "guide"
audience:
  - developers
  - admins
version: "current"
last_updated: "2026-11-18"
---

# Compare

## Compare

A branch comparison lists the differences in content types and global fields between a base branch and a compare branch. Use this class to hold the two branches and the headers and query parameters for that comparison.

stack.branch("<BRANCH>").compare("docs-test-branch") returns a Compare with <BRANCH> as the base branch. The public constructor takes the internal Retrofit instance of the SDK, so use the [compare](/docs/developers/sdks/content-management-sdk/java/reference/branch#branch-compare) method of Branch instead.

Name

Type

Description

branchUid

String

UID of the base branch. Pass it to stack.branch().

compareBranchId

String

UID of the branch to compare. Pass it to compare().

*   **Known issue:** In 1.16.0, Compare has no public method that sends a request, so the SDK cannot run a branch comparison. Send the [Compare branches](/docs/developers/apis/content-management-api/branches#compare-branches) request with another HTTP client.

## addHeader

addHeader adds one request header to this comparison.

```
Returns: Compare. The same comparison, for chaining.
ValidationThere is no client-side validation. A null key or value does not throw here.Nothing reports a bad value, because no public method of Compare sends a request in 1.16.0.BehavioraddHeader stores the header in the header map of this object and sends nothing.A later call with the same name replaces the value.The header goes on the headers of the comparison. In 1.16.0, no public method of Compare sends them, and stays there for every later request.A new Compare object holds only a Content-Type header. It does not carry the api_key and authorization headers of the stack.ExampleBasic usage: add the API key header to a comparisonimport com.contentstack.cms.Contentstack;
import com.contentstack.cms.stack.Compare;

public class CompareHeader {
    public static void main(String[] args) {
        Contentstack client = new Contentstack.Builder().build();

        Compare compare = client.stack("<API_KEY>", "<MANAGEMENT_TOKEN>")
                .branch("main")
                .compare("docs-test-branch")
                .addHeader("api_key", "<API_KEY>");

        // Compare has no public request method in 1.16.0, so the header stays on the object
        System.out.println("Stored the api_key header on the comparison.");
    }
}
```

Name of the header.

Value of the header.

## addHeaders

addHeaders adds every entry of a map to the request headers of this comparison.

```
Returns: Compare. The same comparison, for chaining.
ValidationThrows NullPointerException if headers is null, because addHeaders copies every entry of the map.Nothing reports a bad value, because no public method of Compare sends a request in 1.16.0.BehavioraddHeaders copies the entries into the header map of this object and sends nothing.An entry replaces a header with the same name.The headers go on the headers of the comparison. In 1.16.0, no public method of Compare sends them, and stay there for every later request.A new Compare object holds only a Content-Type header. It does not carry the api_key and authorization headers of the stack.ExampleBasic usage: add the stack credentials to a comparisonimport com.contentstack.cms.Contentstack;
import com.contentstack.cms.stack.Compare;

import java.util.HashMap;

public class CompareHeaders {
    public static void main(String[] args) {
        Contentstack client = new Contentstack.Builder().build();

        HashMap<String, String> headers = new HashMap<>();
        headers.put("api_key", "<API_KEY>");
        headers.put("authorization", "<MANAGEMENT_TOKEN>");

        Compare compare = client.stack("<API_KEY>", "<MANAGEMENT_TOKEN>")
                .branch("main")
                .compare("docs-test-branch")
                .addHeaders(headers);

        // Compare has no public request method in 1.16.0, so the headers stay on the object
        System.out.println("Stored " + headers.size() + " headers on the comparison.");
    }
}
```

Header names mapped to their values.

## addParam

addParam adds one query parameter to this comparison.

```
Returns: Compare. The same comparison, for chaining.
ValidationThere is no client-side validation. A null key or value does not throw here.Nothing reports a bad value, because no public method of Compare sends a request in 1.16.0.BehavioraddParam stores the pair in the query parameter map of this object and sends nothing.A later call with the same key replaces the value.The parameter goes on the query parameters of the comparison. In 1.16.0, no public method of Compare sends them.The parameter stays on the object for every later request.The Compare branches reference lists skip and limit for this request, and include_schemas for the requests on one content type or global field.ExampleBasic usage: set the page size of a comparisonimport com.contentstack.cms.Contentstack;
import com.contentstack.cms.stack.Compare;

public class LimitComparison {
    public static void main(String[] args) {
        Contentstack client = new Contentstack.Builder().build();

        Compare compare = client.stack("<API_KEY>", "<MANAGEMENT_TOKEN>")
                .branch("main")
                .compare("docs-test-branch")
                .addParam("limit", 50);

        // Compare has no public request method in 1.16.0, so the parameter stays on the object
        System.out.println("Stored the limit parameter on the comparison.");
    }
}
```

Name of the query parameter.

Value of the query parameter, sent as its string form.

## addParams

addParams adds every entry of a map to the query parameters of this comparison.

```
Returns: Compare. The same comparison, for chaining.
ValidationThrows NullPointerException if params is null, because addParams copies every entry of the map.Nothing reports a bad value, because no public method of Compare sends a request in 1.16.0.BehavioraddParams copies the entries into the query parameter map of this object and sends nothing.An entry replaces a parameter with the same name.The parameters go on the query parameters of the comparison. In 1.16.0, no public method of Compare sends them.The parameters stay on the object for every later request.The Compare branches reference lists skip and limit for this request, and include_schemas for the requests on one content type or global field.ExampleBasic usage: set several comparison parametersimport com.contentstack.cms.Contentstack;
import com.contentstack.cms.stack.Compare;

import java.util.HashMap;

public class ConfigureComparison {
    public static void main(String[] args) {
        Contentstack client = new Contentstack.Builder().build();

        HashMap<String, Object> params = new HashMap<>();
        params.put("skip", 0);
        params.put("limit", 50);
        params.put("include_schemas", true);

        Compare compare = client.stack("<API_KEY>", "<MANAGEMENT_TOKEN>")
                .branch("main")
                .compare("docs-test-branch")
                .addParams(params);

        // Compare has no public request method in 1.16.0, so the parameters stay on the object
        System.out.println("Stored " + params.size() + " parameters on the comparison.");
    }
}
```

Query parameter names mapped to their values.

## Compare | Java Management SDK | Contentstack

The Compare class in the Java Management SDK holds a base branch, a compare branch, and the headers and query parameters for a branch comparison.