سؤال

I'm VERY newb at Groovy (and most back end.) I'm typically a JS developer, so bear with me.

I have a static .txt file that's holding a manifest, one item per line:

asdf/asdf/rewer.js
asdf/asdf/opuio.js
asdf/asdf/rnieo.js
asdf/asdf/tewoe.js

I have successfully read it with readLines() and converted it to an array using HashSet().

However, this array is not in the original order of the file... nor is it alphabetical. So I'm at a loss how this is being ordered or how to maintain the correct order.

How can order be maintained?

(Don't ask why I'm listing JS files in a .txt and pulling them in this way. It's a crazy, convoluted requirement. Just looking to keep the order.)

Thanks

هل كانت مفيدة؟

المحلول

Is there any reason you are using HashSet for this?

If you want an array of lines you can just convert the list to an array using list.toArray()

def linesAsArray = new File('file.txt').readLines().toArray()
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top