Apply autofit only for outer table not for nested tables

How to apply FIXED_COLUMN_WIDTHS auto fit only for outer table not for nested table.

MY example code :

for (Table table :(Iterable<Table>) document.getChildNodes(NodeType.TABLE, true)) {
    table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
    table.setPreferredWidth(PreferredWidth.fromPercent(100));
}

@jai25 You can use code like this to skip nested tables:

for (Table table :(Iterable<Table>)document.getChildNodes(NodeType.TABLE, true))
{
    if (table.getAncestor(NodeType.TABLE) == null)
    {
        table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
        table.setPreferredWidth(PreferredWidth.fromPercent(100));
    }
}

Thank you for your solution.
I need to set AutoFitBehavior.AUTO_FIT_TO_CONTENTS to cells inside the table with above condition.

@jai25 Alternatively you can loop through the tables that are direct children of Body. For example see the following code:

for (Section s : doc.getSections())
{
    for (Table t : s.getBody().getTables())
    {
        // Do something ith the table.
    }
}

could please provide sample code to set Preferred Width percent to 85 for cells inside the table.
the table is set with below changes
table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
table.setPreferredWidth(PreferredWidth.fromPercent(100));

@jai25 When you use AutoFitBehavior.FIXED_COLUMN_WIDTHS table and cell preferred width are reset. Please see our documentation for more information:
https://docs.aspose.com/words/java/how-to-apply-different-autofit-settings-to-a-table/#disabling-autofitting-on-a-table-and-use-fixed-column-widths
Also, please see the following article to learn more about setting table and cells withs:
https://docs.aspose.com/words/java/specifying-table-and-cell-widths/