1

I have the following extract of code below;

The issue is that

(element.getChildNodes().item(0).getNodeValue())

has output of a differing number of characters

which then causes eventy to be moved out of line with other output from the other rows therefore giving a zig zag appearance of data instead of data in columns, i have tried experimenting with tabs and spaces. But would appreciate some help please.

String eventy = null;

for (int i = 0; i < list.getLength(); i++) {
    Element element = (Element)list.item(i);
    String nodeName = element.getNodeName();

    switch (nodeName) {
        case "assd":
            System.out.println((element.getChildNodes().item(0).getNodeValue()) + "\t  " eventy);
            break;
        case "eventy":
            eventy = element.getChildNodes().item(0).getNodeValue();
            break;
    }
}
0

1 Answer 1

2

If you can assume maximum length of strings from "assd" child node, you could use System.out.printf. For example:

System.out.printf("%-20s   %s%n", element.getChildNodes().item(0).getNodeValue(), eventy)

would print a value of "assd" child node to first column with width 20 then value of variable eventy and then new line separator.

See Format String Syntax

Sign up to request clarification or add additional context in comments.

3 Comments

This works perfectly i dont understand why instead of + eventy it now changes to ,eventy?
similarly if i had another variable called eventyo how would i add that to the output?
worked it out excellent System.out.printf("%-30s %-30s %s%n", element.getChildNodes().item(0).getNodeValue(), eventy,eventyo);

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.