On 02/04/13 13:35, Joerg Meier wrote:
On Tue, 2 Apr 2013 03:11:53 -0700 (PDT), subhabangalore@gmail.com wrote:
I am taking out the files in my desktop folder, as,
[...]
I am getting name of files individually but I want to see them as the
whole bunch like,
myList=["string1","string2","string3",...."StringN"]
You need to move the list assignment out of the loop, like so:
final File folder = new File("G:\\Media\\TV Show");
final ArrayList<String> myList = new ArrayList<String>();
for (final File name : folder.listFiles()) {
final String s1 = name.toString();
System.out.println("####" + s1);
System.out.print(name);
myList.add(s1);
}
Just as a matter of interest what's with all the finals
particularly
for (final File name : folder.listFiles())
Despite initial appearances this is indeed legal as the
assignment is made multiple times but from the same statement.
Given that the final keyword is, aside from a flag to the compiler for
possible optimization, largely documentary, what is the point of making
name final.
In fact what does peppering the code with finals do to make it easily
understandable to an inexperienced developer ?
solid founded in how JVM's from the 1990's worked.
Java a more functional language.
I don't like it. If I want to program in a functional style, then
I would pick a functional language.