-5
public static void printFiles(NodeList node) {
            for (int i = 0; i < node.getLength(); i++) {
                Node file = node.item(i);
                String nodeValue =  file.getAttributes().getNamedItem("urlName").getNodeValue();
                System.out.println(nodeValue);
            }
        }

output:
0a4f171c-e0a4-4aa8-b43b-3989c235ff58.txt
0ccfa1a4-16b0-4e1f-abc9-e17907bb591f.txt
17c0545b-377e-4e0a-bb45-29f38fc91533.txt
3b341bf0-2cd7-46fe-a834-5b67804e5ff1.txt
48121209-d58e-4565-83b7-05062799be6e.txt
511b7a89-e4de-4f6e-9c8f-5ba65f675d7b.txt
compress.txt
dadadada.txt
e0c44cb9-2b1c-444c-a429-64531ea6a9a0.txt
e68b1d1d-9a66-4678-a6c1-76c64ae8be08.txt
hgafgahfka.txt
jdjajhdajdajd.txt
test1.txt
test2.txt

I parsed the xml document and got the values through for loop but those alues need to be in single place like List so that I can pass to some other function.can some one please let me know how to add those in a List .Below is the code and the current Output.

4
  • 1
    Put them into a List then. What's the issue exactly? Commented Apr 14, 2015 at 16:26
  • As @BoristheSpider mention just put your data in a List... You can provide checks if the element look-up in the node exists. That would be safer Commented Apr 14, 2015 at 16:27
  • Welcome to Stack overflow How to ask a question Commented Apr 14, 2015 at 16:28
  • List<String> list = new ArrayList<>(); list.add(nodeValue); Commented Apr 14, 2015 at 16:32

1 Answer 1

0
String input = "hello world";    
List<String> list = new ArrayList<>();
list.add(input);
System.out.println(list.get(0));


> hello world

Good luck

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.