Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 02 Apr 2013 09:08:56 -0500 Date: Tue, 02 Apr 2013 15:08:53 +0100 From: lipska the kat <"nospam at neversurrender dot co dot uk"> Organization: Trollbusters 3 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120410 Thunderbird/11.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Inserting In a List References: <19un43xj77bua.vw45l4e2wshi.dlg@40tude.net> In-Reply-To: <19un43xj77bua.vw45l4e2wshi.dlg@40tude.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 43 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-S23f2sqkxgabC35kIElK0rlk8Zh39yU6BpLdFi7JmpthYbTGNkqr1UhB77GQ+zglQ9yIddrriks48u7!Egt5XXWfsqfGhq27pSWzEye2A+nZxKRi1e8VK8Ck/s9INZQQFe5D6GhZkCjBjzJoCR2tNUHKWSg= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2631 Xref: csiph.com comp.lang.java.programmer:23184 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 myList = new ArrayList(); > 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 ? lipska -- Lipska the KatŠ: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun