Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #23175 > unrolled thread

Inserting In a List

Started bysubhabangalore@gmail.com
First post2013-04-02 03:11 -0700
Last post2013-04-03 10:35 +0100
Articles 20 on this page of 161 — 18 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Inserting In a List subhabangalore@gmail.com - 2013-04-02 03:11 -0700
    Re: Inserting In a List Roedy Green <see_website@mindprod.com.invalid> - 2013-04-02 03:59 -0700
    Re: Inserting In a List Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-02 08:27 -0300
    Re: Inserting In a List Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-02 08:59 -0300
      Re: Inserting In a List Martin Gregorie <martin@address-in-sig.invalid> - 2013-04-02 21:06 +0000
        Re: Inserting In a List Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-02 18:22 -0400
          Re: Inserting In a List Martin Gregorie <martin@address-in-sig.invalid> - 2013-04-02 22:52 +0000
            Re: Inserting In a List Joerg Meier <joergmmeier@arcor.de> - 2013-04-03 02:04 +0200
              Re: Inserting In a List Arne Vajhøj <arne@vajhoej.dk> - 2013-04-02 20:20 -0400
                Re: Inserting In a List Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-02 21:03 -0400
                  Re: Inserting In a List Arne Vajhøj <arne@vajhoej.dk> - 2013-04-02 21:26 -0400
                    Re: Inserting In a List Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-02 22:29 -0400
                      Re: Inserting In a List Arne Vajhøj <arne@vajhoej.dk> - 2013-04-03 20:16 -0400
                Re: Inserting In a List Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2013-04-02 20:26 -0500
                  Re: Inserting In a List Arne Vajhøj <arne@vajhoej.dk> - 2013-04-02 21:29 -0400
                    Re: Inserting In a List Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 14:07 +0200
              Re: Inserting In a List Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-03 05:45 -0300
                Re: Inserting In a List Joerg Meier <joergmmeier@arcor.de> - 2013-04-03 15:26 +0200
                  Re: Inserting In a List Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-03 18:09 -0300
                    Re: Inserting In a List Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 00:54 +0200
                      Re: Inserting In a List Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-03 20:30 -0300
                        Re: Inserting In a List Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 01:35 +0200
                          Re: Inserting In a List Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-03 20:55 -0300
                            Re: Inserting In a List Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 02:00 +0200
                        Re: Inserting In a List Arne Vajhøj <arne@vajhoej.dk> - 2013-04-03 19:49 -0400
              Re: Inserting In a List Martin Gregorie <martin@address-in-sig.invalid> - 2013-04-03 22:43 +0000
                Re: Inserting In a List Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 01:08 +0200
                  Re: Inserting In a List Martin Gregorie <martin@address-in-sig.invalid> - 2013-04-04 00:42 +0000
                    Re: Inserting In a List Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 14:12 +0200
                      Re: Inserting In a List Martin Gregorie <martin@address-in-sig.invalid> - 2013-04-04 21:47 +0000
                        Re: Inserting In a List Joerg Meier <joergmmeier@arcor.de> - 2013-04-05 00:36 +0200
            Re: Inserting In a List Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-02 21:08 -0400
              Re: Inserting In a List Martin Gregorie <martin@address-in-sig.invalid> - 2013-04-03 22:37 +0000
                Re: Inserting In a List Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-03 20:50 -0400
    Re: Inserting In a List Joerg Meier <joergmmeier@arcor.de> - 2013-04-02 14:35 +0200
      Re: Inserting In a List lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-02 15:08 +0100
        Usefulness of "final" (Was: Re: Inserting In a List) Robert Klemme <shortcutter@googlemail.com> - 2013-04-02 21:06 +0200
          Re: Usefulness of "final" (Was: Re: Inserting In a List) Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-02 16:41 -0400
            Re: Usefulness of "final" (Was: Re: Inserting In a List) Robert Klemme <shortcutter@googlemail.com> - 2013-04-03 08:09 +0200
              Re: Usefulness of "final" (Was: Re: Inserting In a List) Arne Vajhøj <arne@vajhoej.dk> - 2013-04-03 20:13 -0400
          Re: Usefulness of "final" (Was: Re: Inserting In a List) Arne Vajhøj <arne@vajhoej.dk> - 2013-04-02 20:08 -0400
          Re: Usefulness of "final" (Was: Re: Inserting In a List) lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-03 11:15 +0100
            Re: Usefulness of "final" (Was: Re: Inserting In a List) Robert Klemme <shortcutter@googlemail.com> - 2013-04-03 19:08 +0200
              Re: Usefulness of "final" (Was: Re: Inserting In a List) lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-03 19:51 +0100
                Re: Usefulness of "final" (Was: Re: Inserting In a List) Joerg Meier <joergmmeier@arcor.de> - 2013-04-03 21:01 +0200
                  Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 14:15 -0700
                    Re: Usefulness of "final" (Was: Re: Inserting In a List) Arne Vajhøj <arne@vajhoej.dk> - 2013-04-03 18:22 -0400
                      Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 15:41 -0700
                        Re: Usefulness of "final" (Was: Re: Inserting In a List) Arne Vajhøj <arne@vajhoej.dk> - 2013-04-03 19:56 -0400
                          Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 16:58 -0700
                            Re: Usefulness of "final" (Was: Re: Inserting In a List) Arne Vajhøj <arne@vajhoej.dk> - 2013-04-03 20:08 -0400
                              Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 17:21 -0700
                                Re: Usefulness of "final" (Was: Re: Inserting In a List) Arne Vajhøj <arne@vajhoej.dk> - 2013-04-03 20:27 -0400
                                  Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 17:34 -0700
                                    Re: Usefulness of "final" (Was: Re: Inserting In a List) Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-03 21:20 -0400
                                      Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 19:17 -0700
                                        Re: Usefulness of "final" (Was: Re: Inserting In a List) Lew <lewbloch@gmail.com> - 2013-04-03 20:45 -0700
                                          Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 21:30 -0700
                                            Re: Usefulness of "final" (Was: Re: Inserting In a List) Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 14:34 +0200
                                              Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-04 09:52 -0700
                                                Re: Usefulness of "final" (Was: Re: Inserting In a List) Joerg Meier <joergmmeier@arcor.de> - 2013-04-05 00:39 +0200
                                            Re: Usefulness of "final" (Was: Re: Inserting In a List) Robert Klemme <shortcutter@googlemail.com> - 2013-04-04 19:50 +0200
                                        Re: Usefulness of "final" (Was: Re: Inserting In a List) Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-04 08:27 -0400
                                          Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-04 09:47 -0700
                                            Re: Usefulness of "final" (Was: Re: Inserting In a List) Robert Klemme <shortcutter@googlemail.com> - 2013-04-04 19:44 +0200
                                              Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-04 11:08 -0700
                                                Re: Usefulness of "final" (Was: Re: Inserting In a List) Robert Klemme <shortcutter@googlemail.com> - 2013-04-04 22:53 +0200
                                                  Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-04 14:29 -0700
                                                    Re: Usefulness of "final" (Was: Re: Inserting In a List) Robert Klemme <shortcutter@googlemail.com> - 2013-04-05 21:54 +0200
                                              Re: Usefulness of "final" (Was: Re: Inserting In a List) lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-04 19:48 +0100
                          Re: Usefulness of "final" (Was: Re: Inserting In a List) Arne Vajhøj <arne@vajhoej.dk> - 2013-04-03 20:05 -0400
                            Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 17:24 -0700
                              Re: Usefulness of "final" (Was: Re: Inserting In a List) Arne Vajhøj <arne@vajhoej.dk> - 2013-04-03 20:32 -0400
                                Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 18:34 -0700
                                  Re: Usefulness of "final" (Was: Re: Inserting In a List) Arne Vajhøj <arne@vajhoej.dk> - 2013-04-03 21:54 -0400
                              Re: Usefulness of "final" (Was: Re: Inserting In a List) Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-03 21:25 -0400
                                Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 18:37 -0700
                                  Re: Usefulness of "final" (Was: Re: Inserting In a List) Arne Vajhøj <arne@vajhoej.dk> - 2013-04-03 21:57 -0400
                                    Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 19:23 -0700
                                    Re: Usefulness of "final" (Was: Re: Inserting In a List) Wanja Gayk <brixomatic@yahoo.com> - 2013-04-06 21:58 +0200
                                      Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-06 17:19 -0700
                                        Re: Usefulness of "final" (Was: Re: Inserting In a List) Wanja Gayk <brixomatic@yahoo.com> - 2013-04-07 17:28 +0200
                                          Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-07 09:02 -0700
                                            Re: Usefulness of "final" (Was: Re: Inserting In a List) Wanja Gayk <brixomatic@yahoo.com> - 2013-04-07 19:20 +0200
                                              Re: Usefulness of "final" (Was: Re: Inserting In a List) Wanja Gayk <brixomatic@yahoo.com> - 2013-04-07 19:24 +0200
                                Re: Usefulness of "final" (Was: Re: Inserting In a List) Lew <lewbloch@gmail.com> - 2013-04-03 18:41 -0700
                              Re: Usefulness of "final" (Was: Re: Inserting In a List) Lew <lewbloch@gmail.com> - 2013-04-03 18:31 -0700
                                Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 18:46 -0700
                                  Re: Usefulness of "final" (Was: Re: Inserting In a List) Lew <lewbloch@gmail.com> - 2013-04-03 20:09 -0700
                                    Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 20:47 -0700
                        Re: Usefulness of "final" Leif Roar Moldskred <leifm@dimnakorr.com> - 2013-04-04 00:42 -0500
                          Re: Usefulness of "final" paul.cager@gmail.com - 2013-04-04 01:55 -0700
                            Re: Usefulness of "final" Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 14:45 +0200
                    Re: Usefulness of "final" (Was: Re: Inserting In a List) Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 00:46 +0200
                      Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 16:10 -0700
                        Re: Usefulness of "final" (Was: Re: Inserting In a List) Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 01:25 +0200
                          Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 16:44 -0700
                            Re: Usefulness of "final" (Was: Re: Inserting In a List) Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 01:57 +0200
                              Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 17:19 -0700
                                Re: Usefulness of "final" (Was: Re: Inserting In a List) Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 14:35 +0200
                                  Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-04 10:34 -0700
                                    Re: Usefulness of "final" (Was: Re: Inserting In a List) Joerg Meier <joergmmeier@arcor.de> - 2013-04-05 00:43 +0200
                                      Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-04 16:22 -0700
                                      Re: Usefulness of "final" (Was: Re: Inserting In a List) Lew <lewbloch@gmail.com> - 2013-04-04 16:49 -0700
                                        Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-04 18:21 -0700
                                          Re: Usefulness of "final" (Was: Re: Inserting In a List) Lew <lewbloch@gmail.com> - 2013-04-04 18:49 -0700
                                            Re: Usefulness of "final" (Was: Re: Inserting In a List) Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-05 05:30 -0300
                            Re: Usefulness of "final" (Was: Re: Inserting In a List) Arne Vajhøj <arne@vajhoej.dk> - 2013-04-03 20:10 -0400
                              Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-03 17:29 -0700
                                Re: Usefulness of "final" (Was: Re: Inserting In a List) Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 02:53 +0200
                                Re: Usefulness of "final" (Was: Re: Inserting In a List) Jim Janney <jjanney@shell.xmission.com> - 2013-04-04 13:51 -0600
                                Re: Usefulness of "final" (Was: Re: Inserting In a List) Robert Klemme <shortcutter@googlemail.com> - 2013-04-06 13:31 +0200
                                  Re: Usefulness of "final" (Was: Re: Inserting In a List) markspace <markspace@nospam.nospam> - 2013-04-06 10:50 -0700
                  Re: Usefulness of "final" (Was: Re: Inserting In a List) lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-04 09:09 +0100
                    Re: Usefulness of "final" (Was: Re: Inserting In a List) Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-04 05:37 -0300
                      Re: Usefulness of "final" (Was: Re: Inserting In a List) Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-04 06:10 -0300
                        Re: Usefulness of "final" (Was: Re: Inserting In a List) Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-04 19:40 -0300
                          Re: arrays and variables Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-05 05:44 -0300
                            Re: arrays and variables lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-05 14:08 +0100
                              Re: arrays and variables Lew <lewbloch@gmail.com> - 2013-04-05 13:33 -0700
                                Re: arrays and variables lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-06 09:11 +0100
                                  Re: arrays and variables Robert Klemme <shortcutter@googlemail.com> - 2013-04-06 15:20 +0200
                                    Re: arrays and variables lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-06 16:25 +0100
                                      Re: arrays and variables Robert Klemme <shortcutter@googlemail.com> - 2013-04-06 17:50 +0200
                                        Re: arrays and variables lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-06 18:13 +0100
                                          Re: arrays and variables Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-06 14:32 -0300
                                Re: arrays and variables Robert Klemme <shortcutter@googlemail.com> - 2013-04-06 15:02 +0200
                            Re: arrays and variables Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-05 22:12 -0300
                      Re: Usefulness of "final" (Was: Re: Inserting In a List) lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-04 10:35 +0100
                        Re: Usefulness of "final" (Was: Re: Inserting In a List) Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 14:02 +0200
                          Re: Usefulness of "final" (Was: Re: Inserting In a List) lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-04 13:41 +0100
                    Re: Usefulness of "final" (Was: Re: Inserting In a List) Joerg Meier <joergmmeier@arcor.de> - 2013-04-04 13:53 +0200
                Re: Usefulness of "final" (Was: Re: Inserting In a List) Robert Klemme <shortcutter@googlemail.com> - 2013-04-03 23:05 +0200
        Re: Inserting In a List Joerg Meier <joergmmeier@arcor.de> - 2013-04-02 22:09 +0200
        Re: Inserting In a List Arne Vajhøj <arne@vajhoej.dk> - 2013-04-02 20:03 -0400
        Re: Inserting In a List Wanja Gayk <brixomatic@yahoo.com> - 2013-04-06 21:39 +0200
          Re: Inserting In a List Robert Klemme <shortcutter@googlemail.com> - 2013-04-07 01:08 +0200
          Re: Inserting In a List Lew <lewbloch@gmail.com> - 2013-04-06 22:15 -0700
            Re: Inserting In a List lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-07 08:48 +0100
              Re: Inserting In a List Lew <lewbloch@gmail.com> - 2013-04-07 12:32 -0700
                Re: Inserting In a List "John B. Matthews" <nospam@nospam.invalid> - 2013-04-07 21:06 -0400
                Re: Inserting In a List lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-08 08:40 +0100
          Re: Inserting In a List lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-07 08:55 +0100
            Re: Inserting In a List Wanja Gayk <brixomatic@yahoo.com> - 2013-04-07 17:54 +0200
              Re: Inserting In a List lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-07 19:53 +0100
                Re: Inserting In a List Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-07 17:58 -0300
                Re: Inserting In a List Robert Klemme <shortcutter@googlemail.com> - 2013-04-08 08:28 +0200
                  Re: Inserting In a List lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-08 08:54 +0100
                    Re: Inserting In a List Robert Klemme <shortcutter@googlemail.com> - 2013-04-08 19:13 +0200
                Re: Inserting In a List Wanja Gayk <brixomatic@yahoo.com> - 2013-04-12 20:58 +0200
                  Re: Inserting In a List Lew <lewbloch@gmail.com> - 2013-04-12 13:17 -0700
              Re: Inserting In a List Lew <lewbloch@gmail.com> - 2013-04-07 12:40 -0700
                Re: Inserting In a List Wanja Gayk <brixomatic@yahoo.com> - 2013-04-12 20:47 +0200
                  Re: Inserting In a List Lew <lewbloch@gmail.com> - 2013-04-12 13:14 -0700
    Re: Inserting In a List Steven Simpson <ss@domain.invalid> - 2013-04-02 13:53 +0100
    Re: Inserting In a List Roedy Green <see_website@mindprod.com.invalid> - 2013-04-02 07:10 -0700
    Re: Inserting In a List Lew <lewbloch@gmail.com> - 2013-04-02 10:46 -0700
      Re: Inserting In a List markspace <markspace@nospam.nospam> - 2013-04-02 11:28 -0700
        Re: Inserting In a List Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-02 16:00 -0400
    Re: Inserting In a List subhabangalore@gmail.com - 2013-04-03 01:47 -0700
      Re: Inserting In a List Steven Simpson <ss@domain.invalid> - 2013-04-03 10:35 +0100

Page 1 of 9  [1] 2 3 4 5 6 7 8 9  Next page →


#23175 — Inserting In a List

Fromsubhabangalore@gmail.com
Date2013-04-02 03:11 -0700
SubjectInserting In a List
Message-ID<d4ecae37-89d4-4747-a8ae-aea86fbbecf2@googlegroups.com>
Dear Group,

I am taking out the files in my desktop folder, as,

File folder = new File("C:\\Users\\subhabrata\\Desktop");

Next, I am trying to take them out one by one as using for loop and name
of each file is converted to String, 

for( File name :folder.listFiles()){
String s1=name.toString(); 
System.out.println("####"+s1);
System.out.print( name );
}

Till this there is no issue, now I am trying to insert name of all the files in an array, generally it can be done, as,

ArrayList<String> myList = new ArrayList<String>();
        myList.add(s1);

But the problem I am facing is, if I put it as,

for( File name :folder.listFiles()){
String s1=name.toString(); 
System.out.println("####"+s1);
System.out.print( name );
ArrayList<String> myList = new ArrayList<String>();
        myList.add(s1);
}

I am getting name of files individually but I want to see them as the whole bunch like,

myList=["string1","string2","string3",...."StringN"]

My aim is to check the names then in another for loop and if match is not found with some defined name update the list.

I am slightly new in Java so if anyone can kindly suggest how I should address it.

Regards,
Subhabrata. 

[toc] | [next] | [standalone]


#23176

FromRoedy Green <see_website@mindprod.com.invalid>
Date2013-04-02 03:59 -0700
Message-ID<efell815gu853hc2hr8s6nt6behhh2ivqv@4ax.com>
In reply to#23175
On Tue, 2 Apr 2013 03:11:53 -0700 (PDT), subhabangalore@gmail.com
wrote, quoted or indirectly quoted someone who said :

>I am getting name of files individually but I want to see them as the whole bunch like,
>
>myList=["string1","string2","string3",...."StringN"]
 
you will need a loop that runs over the list and builds the combined
string.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
Motors make noise, and that tells you about the feelings and attitudes 
that went into it. Something was more important than sensory pleasure -- 
nobody would invent a chair or dish that smelled bad or that made horrible 
noises -- why were motors invented noisy? How could they possibly be 
considered complete or successful inventions with this glaring defect?
Unless, of course, the aggressive, hostile, assaultive sound actually served
to express some impulse of the owner. 
~ Philip Slater (born: 1927 age: 85)
The Wayward Gate: Science and the Supernatural

[toc] | [prev] | [next] | [standalone]


#23177

FromArved Sandstrom <asandstrom2@eastlink.ca>
Date2013-04-02 08:27 -0300
Message-ID<Fgz6t.74180$mC2.41460@newsfe29.iad>
In reply to#23175
On 04/02/2013 07:11 AM, subhabangalore@gmail.com wrote:
> Dear Group,
>
> I am taking out the files in my desktop folder, as,
>
> File folder = new File("C:\\Users\\subhabrata\\Desktop");
>
> Next, I am trying to take them out one by one as using for loop and name
> of each file is converted to String,
>
> for( File name :folder.listFiles()){
> String s1=name.toString();
> System.out.println("####"+s1);
> System.out.print( name );
> }
>
> Till this there is no issue, now I am trying to insert name of all the files in an array, generally it can be done, as,
>
> ArrayList<String> myList = new ArrayList<String>();
>          myList.add(s1);
>
> But the problem I am facing is, if I put it as,
>
> for( File name :folder.listFiles()){
> String s1=name.toString();
> System.out.println("####"+s1);
> System.out.print( name );
> ArrayList<String> myList = new ArrayList<String>();
>          myList.add(s1);
> }
>
> I am getting name of files individually but I want to see them as the whole bunch like,
>
> myList=["string1","string2","string3",...."StringN"]
>
> My aim is to check the names then in another for loop and if match is not found with some defined name update the list.
>
> I am slightly new in Java so if anyone can kindly suggest how I should address it.
>
> Regards,
> Subhabrata.
>
This comes up every so often. Guava and Apache StringUtils have 
join-type methods for concatenating list elements with a delimiter of 
your choice.

Fact is, though, if you just want a readable debugging print of your 
List, did you not simply try

System.out.println(myList);

AHS

[toc] | [prev] | [next] | [standalone]


#23179

FromArved Sandstrom <asandstrom2@eastlink.ca>
Date2013-04-02 08:59 -0300
Message-ID<ZKz6t.393788$kp4.308027@newsfe09.iad>
In reply to#23175
On 04/02/2013 08:40 AM, Stefan Ram wrote:
> subhabangalore@gmail.com writes:
>> for( File name :folder.listFiles()){
>> String s1=name.toString();
>> System.out.println("####"+s1);
>> System.out.print( name );
>> ArrayList<String> myList = new ArrayList<String>();
>>         myList.add(s1);
>> }
>
>    I see two answers in this NG both not mentioning what is
>    sticking out like a sore thumb from this code: The line
>
> ArrayList<String> myList = new ArrayList<String>();
>
>    is within the for-loop, while it obviously should appear in
>    front of it. (There might be other issues I am not aware of,
>    but this one I saw immediately.)
>
You've got a point there. :-) Well, many pairs of eyes in a review is 
always better than one.

AHS

[toc] | [prev] | [next] | [standalone]


#23193

FromMartin Gregorie <martin@address-in-sig.invalid>
Date2013-04-02 21:06 +0000
Message-ID<kjfh97$i51$3@localhost.localdomain>
In reply to#23179
On Tue, 02 Apr 2013 08:59:52 -0300, Arved Sandstrom wrote:

> On 04/02/2013 08:40 AM, Stefan Ram wrote:
>> subhabangalore@gmail.com writes:
>>> for( File name :folder.listFiles()){
>>> String s1=name.toString(); System.out.println("####"+s1);
>>> System.out.print( name );
>>> ArrayList<String> myList = new ArrayList<String>();
>>>         myList.add(s1);
>>> }
>>
>>    I see two answers in this NG both not mentioning what is sticking
>>    out like a sore thumb from this code: The line
>>
>> ArrayList<String> myList = new ArrayList<String>();
>>
>>    is within the for-loop, while it obviously should appear in front of
>>    it. (There might be other issues I am not aware of,
>>    but this one I saw immediately.)
>>
> You've got a point there. :-) Well, many pairs of eyes in a review is
> always better than one.
> 
Its also not clear to me whether the OP is expecting some form of sorted 
list of filenames. If he is expecting that, it would be best to use a 
TreeMap<String> rather than an ArrayList<String> to store the filenames.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

[toc] | [prev] | [next] | [standalone]


#23196

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2013-04-02 18:22 -0400
Message-ID<kjfljm$fej$1@dont-email.me>
In reply to#23193
On 4/2/2013 5:06 PM, Martin Gregorie wrote:
>[...]
> Its also not clear to me whether the OP is expecting some form of sorted
> list of filenames. If he is expecting that, it would be best to use a
> TreeMap<String> rather than an ArrayList<String> to store the filenames.

     Is there a reason to prefer TreeMap (or other SortedMap) over
accumulate-disordered-and-sort-afterward?

-- 
Eric Sosman
esosman@comcast-dot-net.invalid

[toc] | [prev] | [next] | [standalone]


#23198

FromMartin Gregorie <martin@address-in-sig.invalid>
Date2013-04-02 22:52 +0000
Message-ID<kjfnf3$k7l$1@localhost.localdomain>
In reply to#23196
On Tue, 02 Apr 2013 18:22:55 -0400, Eric Sosman wrote:

> On 4/2/2013 5:06 PM, Martin Gregorie wrote:
>>[...]
>> Its also not clear to me whether the OP is expecting some form of
>> sorted list of filenames. If he is expecting that, it would be best to
>> use a TreeMap<String> rather than an ArrayList<String> to store the
>> filenames.
> 
>      Is there a reason to prefer TreeMap (or other SortedMap) over
> accumulate-disordered-and-sort-afterward?
>
I think so, yes, because none of File's list() and listFiles() methods 
guarantee the order of the returned files. By using TreeMap or equivalent 
the OP gets the sort for free, should it be required.

I use it a lot, both for that and because accessing stored objects by key 
from a TreeMap is almost certainly faster than scanning an ArrayMap 
unless it contains very few objects indeed. 


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

[toc] | [prev] | [next] | [standalone]


#23200

FromJoerg Meier <joergmmeier@arcor.de>
Date2013-04-03 02:04 +0200
Message-ID<1vzadyb0cgq7k.rsclf5bucb9k$.dlg@40tude.net>
In reply to#23198
On Tue, 2 Apr 2013 22:52:20 +0000 (UTC), Martin Gregorie wrote:

> On Tue, 02 Apr 2013 18:22:55 -0400, Eric Sosman wrote:
>> On 4/2/2013 5:06 PM, Martin Gregorie wrote:
>>>[...]
>>> Its also not clear to me whether the OP is expecting some form of
>>> sorted list of filenames. If he is expecting that, it would be best to
>>> use a TreeMap<String> rather than an ArrayList<String> to store the
>>> filenames.
>>      Is there a reason to prefer TreeMap (or other SortedMap) over
>> accumulate-disordered-and-sort-afterward?
> I think so, yes, because none of File's list() and listFiles() methods 
> guarantee the order of the returned files. By using TreeMap or equivalent 
> the OP gets the sort for free, should it be required.

For free ? The cost is just distributed amongst the insert calls, and is
likely considerably higher than with an unsorted list that has a single
sort call once it is filled. SortedMaps are for things that need sorting
accessible before all elements are inserted, which really isn't the case
here.

> I use it a lot, both for that and because accessing stored objects by key 
> from a TreeMap is almost certainly faster than scanning an ArrayMap 
> unless it contains very few objects indeed.

Java doesn't have ArrayMaps. TreeMaps are O(log(n)) for get while a HashMap
alternative would be O(1). I don't think Java includes any map with
behaviour as ill coded as what you describe. Frankly, I'm having trouble
imagining any modern language having something quite that horrible. Even
LinkedList-Map-combinations usually are backed with some sort of HashMap.

I don't mean to be rude, but it seems like you have lot of misconception
about how data structures work in anything more than school/class level
implementations.

Liebe Gruesse,
		Joerg

-- 
Ich lese meine Emails nicht, replies to Email bleiben also leider
ungelesen.

[toc] | [prev] | [next] | [standalone]


#23202

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-04-02 20:20 -0400
Message-ID<515b75bf$0$32104$14726298@news.sunsite.dk>
In reply to#23200
On 4/2/2013 8:04 PM, Joerg Meier wrote:
> On Tue, 2 Apr 2013 22:52:20 +0000 (UTC), Martin Gregorie wrote:
>
>> On Tue, 02 Apr 2013 18:22:55 -0400, Eric Sosman wrote:
>>> On 4/2/2013 5:06 PM, Martin Gregorie wrote:
>>>> [...]
>>>> Its also not clear to me whether the OP is expecting some form of
>>>> sorted list of filenames. If he is expecting that, it would be best to
>>>> use a TreeMap<String> rather than an ArrayList<String> to store the
>>>> filenames.
>>>       Is there a reason to prefer TreeMap (or other SortedMap) over
>>> accumulate-disordered-and-sort-afterward?
>> I think so, yes, because none of File's list() and listFiles() methods
>> guarantee the order of the returned files. By using TreeMap or equivalent
>> the OP gets the sort for free, should it be required.
>
> For free ? The cost is just distributed amongst the insert calls, and is
> likely considerably higher than with an unsorted list that has a single
> sort call once it is filled.

It is not that obvious to me that:

n O(1) + 1 O(nlogn) is that much faster than n log(n)

>                                 SortedMaps are for things that need sorting
> accessible before all elements are inserted, which really isn't the case
> here.
>
>> I use it a lot, both for that and because accessing stored objects by key
>> from a TreeMap is almost certainly faster than scanning an ArrayMap
>> unless it contains very few objects indeed.
>
> Java doesn't have ArrayMaps. TreeMaps are O(log(n)) for get while a HashMap
> alternative would be O(1). I don't think Java includes any map with
> behaviour as ill coded as what you describe. Frankly, I'm having trouble
> imagining any modern language having something quite that horrible. Even
> LinkedList-Map-combinations usually are backed with some sort of HashMap.
>
> I don't mean to be rude, but it seems like you have lot of misconception
> about how data structures work in anything more than school/class level
> implementations.

I think Martin has a lot of experience.

But I think he got this post garbled up a bit.

As you correctly state then there are no ArrayMap. I am not even sure
what such a beast would actually do.

I also somewhat suspect that he really meant TreeSet not TreeMap as
I can not see any key value pair here.

Arne

[toc] | [prev] | [next] | [standalone]


#23203

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2013-04-02 21:03 -0400
Message-ID<kjfv1g$3v3$1@dont-email.me>
In reply to#23202
On 4/2/2013 8:20 PM, Arne Vajhøj wrote:
> On 4/2/2013 8:04 PM, Joerg Meier wrote:
>> On Tue, 2 Apr 2013 22:52:20 +0000 (UTC), Martin Gregorie wrote:
>>
>>> On Tue, 02 Apr 2013 18:22:55 -0400, Eric Sosman wrote:
>>>> On 4/2/2013 5:06 PM, Martin Gregorie wrote:
>>>>> [...]
>>>>> Its also not clear to me whether the OP is expecting some form of
>>>>> sorted list of filenames. If he is expecting that, it would be best to
>>>>> use a TreeMap<String> rather than an ArrayList<String> to store the
>>>>> filenames.
>>>>       Is there a reason to prefer TreeMap (or other SortedMap) over
>>>> accumulate-disordered-and-sort-afterward?
>>> I think so, yes, because none of File's list() and listFiles() methods
>>> guarantee the order of the returned files. By using TreeMap or
>>> equivalent
>>> the OP gets the sort for free, should it be required.
>>
>> For free ? The cost is just distributed amongst the insert calls, and is
>> likely considerably higher than with an unsorted list that has a single
>> sort call once it is filled.
>
> It is not that obvious to me that:
>
> n O(1) + 1 O(nlogn) is that much faster than n log(n)

     By design, O() obscures all the coefficients.  If you were
to say that n*log(n) and 9999999999999999999999999999*n*log(n)
are both O(n*log(n)) you would be right -- but if you were to
claim the former was not "that much faster" than the latter you
would be wrong by a factor of 9999999999999999999999999999.

     ... and that's the gist of my question: It seems to me likely
that the actual time to sort an ArrayList of large-ish N size will
be less than the time to build a TreeMap (BTW, Martin probably
meant TreeSet) of the same N items.  Argument: The TreeSet expends
effort in keeping itself always sorted all the time, while the
ArrayList has the freedom to be disordered up until the end, and
then to impose an ordering just once.  The ArrayList is asked to
present one sorted version of N items, while the TreeSet must
offer sorted versions of 1,2,3,...,N items.  If the intermediate
orderings are not required, I don't see much reason to compute them.

     By the way, the ArrayList will use less memory -- but both
will use O(n) in all, so who cares?  :-)

     For this insight I will charge you only O(1) pfennigs. ;-)

-- 
Eric Sosman
esosman@comcast-dot-net.invalid

[toc] | [prev] | [next] | [standalone]


#23206

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-04-02 21:26 -0400
Message-ID<515b8557$0$32106$14726298@news.sunsite.dk>
In reply to#23203
On 4/2/2013 9:03 PM, Eric Sosman wrote:
> On 4/2/2013 8:20 PM, Arne Vajhøj wrote:
>> On 4/2/2013 8:04 PM, Joerg Meier wrote:
>>> On Tue, 2 Apr 2013 22:52:20 +0000 (UTC), Martin Gregorie wrote:
>>>
>>>> On Tue, 02 Apr 2013 18:22:55 -0400, Eric Sosman wrote:
>>>>> On 4/2/2013 5:06 PM, Martin Gregorie wrote:
>>>>>> [...]
>>>>>> Its also not clear to me whether the OP is expecting some form of
>>>>>> sorted list of filenames. If he is expecting that, it would be
>>>>>> best to
>>>>>> use a TreeMap<String> rather than an ArrayList<String> to store the
>>>>>> filenames.
>>>>>       Is there a reason to prefer TreeMap (or other SortedMap) over
>>>>> accumulate-disordered-and-sort-afterward?
>>>> I think so, yes, because none of File's list() and listFiles() methods
>>>> guarantee the order of the returned files. By using TreeMap or
>>>> equivalent
>>>> the OP gets the sort for free, should it be required.
>>>
>>> For free ? The cost is just distributed amongst the insert calls, and is
>>> likely considerably higher than with an unsorted list that has a single
>>> sort call once it is filled.
>>
>> It is not that obvious to me that:
>>
>> n O(1) + 1 O(nlogn) is that much faster than n log(n)
>
>      By design, O() obscures all the coefficients.   If you were
> to say that n*log(n) and 9999999999999999999999999999*n*log(n)
> are both O(n*log(n)) you would be right -- but if you were to
> claim the former was not "that much faster" than the latter you
> would be wrong by a factor of 9999999999999999999999999999.

Yes.

But given same big-O I would expect some solid reasons for a
big difference in coefficients before I assume a big difference
in performance.

>      ... and that's the gist of my question: It seems to me likely
> that the actual time to sort an ArrayList of large-ish N size will
> be less than the time to build a TreeMap (BTW, Martin probably
> meant TreeSet) of the same N items.  Argument: The TreeSet expends
> effort in keeping itself always sorted all the time, while the
> ArrayList has the freedom to be disordered up until the end, and
> then to impose an ordering just once.  The ArrayList is asked to
> present one sorted version of N items, while the TreeSet must
> offer sorted versions of 1,2,3,...,N items.  If the intermediate
> orderings are not required, I don't see much reason to compute them.

I can follow you so far that TreeSort is likely a bit slower
than the ArrayList sort.

But I can not see any reason to expect a big difference.

It is fundamentally the same divide and conquer principle
applied.

Arne

[toc] | [prev] | [next] | [standalone]


#23208

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2013-04-02 22:29 -0400
Message-ID<kjg42l$tfm$1@dont-email.me>
In reply to#23206
On 4/2/2013 9:26 PM, Arne Vajhøj wrote:
> On 4/2/2013 9:03 PM, Eric Sosman wrote:
>> On 4/2/2013 8:20 PM, Arne Vajhøj wrote:
>>> On 4/2/2013 8:04 PM, Joerg Meier wrote:
>>>> On Tue, 2 Apr 2013 22:52:20 +0000 (UTC), Martin Gregorie wrote:
>>>>
>>>>> On Tue, 02 Apr 2013 18:22:55 -0400, Eric Sosman wrote:
>>>>>> On 4/2/2013 5:06 PM, Martin Gregorie wrote:
>>>>>>> [...]
>>>>>>> Its also not clear to me whether the OP is expecting some form of
>>>>>>> sorted list of filenames. If he is expecting that, it would be
>>>>>>> best to
>>>>>>> use a TreeMap<String> rather than an ArrayList<String> to store the
>>>>>>> filenames.
>>>>>>       Is there a reason to prefer TreeMap (or other SortedMap) over
>>>>>> accumulate-disordered-and-sort-afterward?
>>>>> I think so, yes, because none of File's list() and listFiles() methods
>>>>> guarantee the order of the returned files. By using TreeMap or
>>>>> equivalent
>>>>> the OP gets the sort for free, should it be required.
>>>>
>>>> For free ? The cost is just distributed amongst the insert calls,
>>>> and is
>>>> likely considerably higher than with an unsorted list that has a single
>>>> sort call once it is filled.
>>>
>>> It is not that obvious to me that:
>>>
>>> n O(1) + 1 O(nlogn) is that much faster than n log(n)
>>
>>      By design, O() obscures all the coefficients.   If you were
>> to say that n*log(n) and 9999999999999999999999999999*n*log(n)
>> are both O(n*log(n)) you would be right -- but if you were to
>> claim the former was not "that much faster" than the latter you
>> would be wrong by a factor of 9999999999999999999999999999.
>
> Yes.
>
> But given same big-O I would expect some solid reasons for a
> big difference in coefficients before I assume a big difference
> in performance.
>
>>      ... and that's the gist of my question: It seems to me likely
>> that the actual time to sort an ArrayList of large-ish N size will
>> be less than the time to build a TreeMap (BTW, Martin probably
>> meant TreeSet) of the same N items.  Argument: The TreeSet expends
>> effort in keeping itself always sorted all the time, while the
>> ArrayList has the freedom to be disordered up until the end, and
>> then to impose an ordering just once.  The ArrayList is asked to
>> present one sorted version of N items, while the TreeSet must
>> offer sorted versions of 1,2,3,...,N items.  If the intermediate
>> orderings are not required, I don't see much reason to compute them.
>
> I can follow you so far that TreeSort is likely a bit slower
> than the ArrayList sort.
>
> But I can not see any reason to expect a big difference.
>
> It is fundamentally the same divide and conquer principle
> applied.

     The original assertion is "it would be *best* [emphasis mine]
to use a TreeMap<String> [sic] rather than an ArrayList<String>".
I'm not claiming that the difference is "big," nor even that the
difference is "important" -- for reasonably-sized directories, at
any rate.  What I'm questioning is "best."

     Also, I dispute "fundamentally the same."  There is, I think,
a "fundamental" difference between a scheme that makes a sorted
traversal possible once at the end of things and a scheme that
promises such a traversal at every single intermediate stage.
The latter, it seems to me, necessarily does more work because it
adheres to a guarantee at points 1,2,...,N instead of at N only.

-- 
Eric Sosman
esosman@comcast-dot-net.invalid

[toc] | [prev] | [next] | [standalone]


#23253

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-04-03 20:16 -0400
Message-ID<515cc64c$0$32111$14726298@news.sunsite.dk>
In reply to#23208
On 4/2/2013 10:29 PM, Eric Sosman wrote:
> On 4/2/2013 9:26 PM, Arne Vajhøj wrote:
>> On 4/2/2013 9:03 PM, Eric Sosman wrote:
>>> On 4/2/2013 8:20 PM, Arne Vajhøj wrote:
>>>> On 4/2/2013 8:04 PM, Joerg Meier wrote:
>>>>> On Tue, 2 Apr 2013 22:52:20 +0000 (UTC), Martin Gregorie wrote:
>>>>>
>>>>>> On Tue, 02 Apr 2013 18:22:55 -0400, Eric Sosman wrote:
>>>>>>> On 4/2/2013 5:06 PM, Martin Gregorie wrote:
>>>>>>>> [...]
>>>>>>>> Its also not clear to me whether the OP is expecting some form of
>>>>>>>> sorted list of filenames. If he is expecting that, it would be
>>>>>>>> best to
>>>>>>>> use a TreeMap<String> rather than an ArrayList<String> to store the
>>>>>>>> filenames.
>>>>>>>       Is there a reason to prefer TreeMap (or other SortedMap) over
>>>>>>> accumulate-disordered-and-sort-afterward?
>>>>>> I think so, yes, because none of File's list() and listFiles()
>>>>>> methods
>>>>>> guarantee the order of the returned files. By using TreeMap or
>>>>>> equivalent
>>>>>> the OP gets the sort for free, should it be required.
>>>>>
>>>>> For free ? The cost is just distributed amongst the insert calls,
>>>>> and is
>>>>> likely considerably higher than with an unsorted list that has a
>>>>> single
>>>>> sort call once it is filled.
>>>>
>>>> It is not that obvious to me that:
>>>>
>>>> n O(1) + 1 O(nlogn) is that much faster than n log(n)
>>>
>>>      By design, O() obscures all the coefficients.   If you were
>>> to say that n*log(n) and 9999999999999999999999999999*n*log(n)
>>> are both O(n*log(n)) you would be right -- but if you were to
>>> claim the former was not "that much faster" than the latter you
>>> would be wrong by a factor of 9999999999999999999999999999.
>>
>> Yes.
>>
>> But given same big-O I would expect some solid reasons for a
>> big difference in coefficients before I assume a big difference
>> in performance.
>>
>>>      ... and that's the gist of my question: It seems to me likely
>>> that the actual time to sort an ArrayList of large-ish N size will
>>> be less than the time to build a TreeMap (BTW, Martin probably
>>> meant TreeSet) of the same N items.  Argument: The TreeSet expends
>>> effort in keeping itself always sorted all the time, while the
>>> ArrayList has the freedom to be disordered up until the end, and
>>> then to impose an ordering just once.  The ArrayList is asked to
>>> present one sorted version of N items, while the TreeSet must
>>> offer sorted versions of 1,2,3,...,N items.  If the intermediate
>>> orderings are not required, I don't see much reason to compute them.
>>
>> I can follow you so far that TreeSort is likely a bit slower
>> than the ArrayList sort.
>>
>> But I can not see any reason to expect a big difference.
>>
>> It is fundamentally the same divide and conquer principle
>> applied.
>
>      The original assertion is "it would be *best* [emphasis mine]
> to use a TreeMap<String> [sic] rather than an ArrayList<String>".
> I'm not claiming that the difference is "big," nor even that the
> difference is "important" -- for reasonably-sized directories, at
> any rate.  What I'm questioning is "best."

But I did not comment on Martin's "best".

I commented on Joerg's "likely considerably higher".

Arne

[toc] | [prev] | [next] | [standalone]


#23205

FromJoshua Cranmer 🐧 <Pidgeot18@verizon.invalid>
Date2013-04-02 20:26 -0500
Message-ID<kjg0b3$atg$1@dont-email.me>
In reply to#23202
On 4/2/2013 7:20 PM, Arne Vajhøj wrote:
> On 4/2/2013 8:04 PM, Joerg Meier wrote:
>> On Tue, 2 Apr 2013 22:52:20 +0000 (UTC), Martin Gregorie wrote:
>>
>>> On Tue, 02 Apr 2013 18:22:55 -0400, Eric Sosman wrote:
>>>> On 4/2/2013 5:06 PM, Martin Gregorie wrote:
>>>>> [...]
>>>>> Its also not clear to me whether the OP is expecting some form of
>>>>> sorted list of filenames. If he is expecting that, it would be best to
>>>>> use a TreeMap<String> rather than an ArrayList<String> to store the
>>>>> filenames.
>>>>       Is there a reason to prefer TreeMap (or other SortedMap) over
>>>> accumulate-disordered-and-sort-afterward?
>>> I think so, yes, because none of File's list() and listFiles() methods
>>> guarantee the order of the returned files. By using TreeMap or
>>> equivalent
>>> the OP gets the sort for free, should it be required.
>>
>> For free ? The cost is just distributed amongst the insert calls, and is
>> likely considerably higher than with an unsorted list that has a single
>> sort call once it is filled.
>
> It is not that obvious to me that:
>
> n O(1) + 1 O(nlogn) is that much faster than n log(n)

The received wisdom I've heard would say that ArrayList is superior here 
to a TreeMap. Recall that a TreeMap is a self-balancing red-black tree. 
This means that every access of a node requires chasing at most O(lg n) 
pointers, and that adding elements could require as many as O(lg n) 
rebalancing operations. Compare this to ArrayList and the corresponding 
sort technique, which is a merge sort. The array options chase 
effectively no pointers (internal to the data structure), so the 
accesses are predictable to the cache lines. As a result, you would 
expect that the ArrayList+sort method is slightly faster in the general 
case than the TreeMap implementation.

Another factor to keep in mind is algorithmic performance if the data 
isn't actually uniformly random. If the input data is already sorted, 
the sort function will likely achieve its best possible performance, 
while the tree map will likely achieve its worst possible performance. 
Since sorted data tends to be more realistic in practice than true 
random, sorted lists actually have some things going for them. :-)

-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth

[toc] | [prev] | [next] | [standalone]


#23207

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-04-02 21:29 -0400
Message-ID<515b85fc$0$32106$14726298@news.sunsite.dk>
In reply to#23205
On 4/2/2013 9:26 PM, Joshua Cranmer 🐧 wrote:
> On 4/2/2013 7:20 PM, Arne Vajhøj wrote:
>> On 4/2/2013 8:04 PM, Joerg Meier wrote:
>>> On Tue, 2 Apr 2013 22:52:20 +0000 (UTC), Martin Gregorie wrote:
>>>
>>>> On Tue, 02 Apr 2013 18:22:55 -0400, Eric Sosman wrote:
>>>>> On 4/2/2013 5:06 PM, Martin Gregorie wrote:
>>>>>> [...]
>>>>>> Its also not clear to me whether the OP is expecting some form of
>>>>>> sorted list of filenames. If he is expecting that, it would be
>>>>>> best to
>>>>>> use a TreeMap<String> rather than an ArrayList<String> to store the
>>>>>> filenames.
>>>>>       Is there a reason to prefer TreeMap (or other SortedMap) over
>>>>> accumulate-disordered-and-sort-afterward?
>>>> I think so, yes, because none of File's list() and listFiles() methods
>>>> guarantee the order of the returned files. By using TreeMap or
>>>> equivalent
>>>> the OP gets the sort for free, should it be required.
>>>
>>> For free ? The cost is just distributed amongst the insert calls, and is
>>> likely considerably higher than with an unsorted list that has a single
>>> sort call once it is filled.
>>
>> It is not that obvious to me that:
>>
>> n O(1) + 1 O(nlogn) is that much faster than n log(n)
>
> The received wisdom I've heard would say that ArrayList is superior here
> to a TreeMap. Recall that a TreeMap is a self-balancing red-black tree.
> This means that every access of a node requires chasing at most O(lg n)
> pointers, and that adding elements could require as many as O(lg n)
> rebalancing operations. Compare this to ArrayList and the corresponding
> sort technique, which is a merge sort. The array options chase
> effectively no pointers (internal to the data structure), so the
> accesses are predictable to the cache lines. As a result, you would
> expect that the ArrayList+sort method is slightly faster in the general
> case than the TreeMap implementation.

I do not have a problem with 'slightly'.

> Another factor to keep in mind is algorithmic performance if the data
> isn't actually uniformly random. If the input data is already sorted,
> the sort function will likely achieve its best possible performance,
> while the tree map will likely achieve its worst possible performance.
> Since sorted data tends to be more realistic in practice than true
> random, sorted lists actually have some things going for them. :-)

Also true.

Arne

[toc] | [prev] | [next] | [standalone]


#23292

FromJoerg Meier <joergmmeier@arcor.de>
Date2013-04-04 14:07 +0200
Message-ID<6hghvfm01yj0$.1ibg002vs87be.dlg@40tude.net>
In reply to#23207
On Tue, 02 Apr 2013 21:29:32 -0400, Arne Vajhøj wrote:

> I do not have a problem with 'slightly'.

I would be willing to settle on that as well after some more consideration.
My statement was in the heat of the moment, considering the overhead of
many small sort steps compared to one big, optimized sorting loop, but in
retrospect, that is unlikely to make as large an impact as I initially
thought.

If I get bored enough, I'll write some sort of benchmark, but I can't think
of a good way to get realistic 'somewhat sorted' test data, since honestly
the IO of getting filenames would completely crush any possible sort cost
on something that numbers so small.

Liebe Gruesse,
		Joerg

-- 
Ich lese meine Emails nicht, replies to Email bleiben also leider
ungelesen.

[toc] | [prev] | [next] | [standalone]


#23212

FromArved Sandstrom <asandstrom2@eastlink.ca>
Date2013-04-03 05:45 -0300
Message-ID<0%R6t.4243$qE5.2993@newsfe01.iad>
In reply to#23200
On 04/02/2013 09:04 PM, Joerg Meier wrote:
> On Tue, 2 Apr 2013 22:52:20 +0000 (UTC), Martin Gregorie wrote:
>
>> On Tue, 02 Apr 2013 18:22:55 -0400, Eric Sosman wrote:
>>> On 4/2/2013 5:06 PM, Martin Gregorie wrote:
>>>> [...]
>>>> Its also not clear to me whether the OP is expecting some form of
>>>> sorted list of filenames. If he is expecting that, it would be best to
>>>> use a TreeMap<String> rather than an ArrayList<String> to store the
>>>> filenames.
>>>       Is there a reason to prefer TreeMap (or other SortedMap) over
>>> accumulate-disordered-and-sort-afterward?
>> I think so, yes, because none of File's list() and listFiles() methods
>> guarantee the order of the returned files. By using TreeMap or equivalent
>> the OP gets the sort for free, should it be required.
>
> For free ? The cost is just distributed amongst the insert calls, and is
> likely considerably higher than with an unsorted list that has a single
> sort call once it is filled. SortedMaps are for things that need sorting
> accessible before all elements are inserted, which really isn't the case
> here.
>
>> I use it a lot, both for that and because accessing stored objects by key
>> from a TreeMap is almost certainly faster than scanning an ArrayMap
>> unless it contains very few objects indeed.
>
> Java doesn't have ArrayMaps.

[SNIP]

Well, Java actually does have ArrayMaps, if one is willing to include 
published APIs other than those of the JDK. MyFaces, and Google API Java 
Client, and Oracle Fusion Middleware Java API have similar ones, and 
from the Javadocs (they all essentially boil down to "good for small 
number of entries") they even resemble Martin's description.

AHS

[toc] | [prev] | [next] | [standalone]


#23218

FromJoerg Meier <joergmmeier@arcor.de>
Date2013-04-03 15:26 +0200
Message-ID<7kdap78bjeaq.12c828s698i8n$.dlg@40tude.net>
In reply to#23212
On Wed, 03 Apr 2013 05:45:46 -0300, Arved Sandstrom wrote:

> On 04/02/2013 09:04 PM, Joerg Meier wrote:
>> Java doesn't have ArrayMaps.
> [SNIP]

> Well, Java actually does have ArrayMaps, if one is willing to include 
> published APIs other than those of the JDK.

If one is willing to do that, the expression "Java has" or "Java doesn't
have" becomes effictively meaningless.

For example, would you consider the following statements to be true ?

Java has a 'val' data type.
Java has an OpenGL 3D engine.
Java has automatic getter and setter generation.
Java has voice recognition.
Java has function pointers.
Java has delegates.

I think most people would say those, as well as "Java has ArrayMaps", are
wrong. There is relatively little point to asking if a language the size
and popularity of Java has something 3rd party created.

In other words: no, when I say "Java doesn't have xxx", I don't count third
party libraries, and I have trouble believing most other people would.

Liebe Gruesse,
		Joerg

-- 
Ich lese meine Emails nicht, replies to Email bleiben also leider
ungelesen.

[toc] | [prev] | [next] | [standalone]


#23225

FromArved Sandstrom <asandstrom2@eastlink.ca>
Date2013-04-03 18:09 -0300
Message-ID<lU07t.406697$uU.402838@newsfe11.iad>
In reply to#23218
On 04/03/2013 10:26 AM, Joerg Meier wrote:
> On Wed, 03 Apr 2013 05:45:46 -0300, Arved Sandstrom wrote:
>
>> On 04/02/2013 09:04 PM, Joerg Meier wrote:
>>> Java doesn't have ArrayMaps.
>> [SNIP]
>
>> Well, Java actually does have ArrayMaps, if one is willing to include
>> published APIs other than those of the JDK.
>
> If one is willing to do that, the expression "Java has" or "Java doesn't
> have" becomes effictively meaningless.
>
> For example, would you consider the following statements to be true ?
>
> Java has a 'val' data type.
> Java has an OpenGL 3D engine.
> Java has automatic getter and setter generation.
> Java has voice recognition.
> Java has function pointers.
> Java has delegates.
>
> I think most people would say those, as well as "Java has ArrayMaps", are
> wrong. There is relatively little point to asking if a language the size
> and popularity of Java has something 3rd party created.
>
> In other words: no, when I say "Java doesn't have xxx", I don't count third
> party libraries, and I have trouble believing most other people would.
>
> Liebe Gruesse,
> 		Joerg
>
If we're going to be pedantic I might as well add that I wouldn't myself 
say that Java has ArrayLists or HashMaps either. I consider "Java" to be 
the language. If we're going to talk official libraries you'd have to 
refer to a specific version of J2SE/Java SE or J2EE/Java EE, for example.

Having said that, I think the pragmatic question would be (or would have 
been), are there reliable libraries available for a Java programmer to 
do X? In many cases, both now and historically, if one were to adopt 
your narrower definition, one would have to admit that X cannot be 
easily done with just the Java language and official platform 
APIs/implementations, not without a great deal of coding, whereas in 
reality people would be availing themselves of well-known 3rd party 
libraries to do just that.

AHS

[toc] | [prev] | [next] | [standalone]


#23236

FromJoerg Meier <joergmmeier@arcor.de>
Date2013-04-04 00:54 +0200
Message-ID<1jv7xu202lf6n.23ww8r6bftrt.dlg@40tude.net>
In reply to#23225
On Wed, 03 Apr 2013 18:09:36 -0300, Arved Sandstrom wrote:

> If we're going to be pedantic I might as well add that I wouldn't myself 
> say that Java has ArrayLists or HashMaps either. I consider "Java" to be 
> the language. If we're going to talk official libraries you'd have to 
> refer to a specific version of J2SE/Java SE or J2EE/Java EE, for example.

You can feel free to say whatever you want, but lets be realistic: the
majority of people will say "Java has" for stuff in the JCL, and "Java
doesn't have" for stuff not in the JCL. And I am 99% certain that if I had
asked you any of the examples above, you would have said "No, Java doesn't
have a val data type", and you would have says "Yes, Java has a hash map,
it's java.util.HashMap".

You can be pedantic all you want, but I would argue that "stuff in the JCL"
is the definition used by the vast majority of people and really the only
one that makes much sense.

> Having said that, I think the pragmatic question would be (or would have 
> been), are there reliable libraries available for a Java programmer to 
> do X? In many cases, both now and historically, if one were to adopt 
> your narrower definition, one would have to admit that X cannot be 
> easily done with just the Java language and official platform 
> APIs/implementations, not without a great deal of coding, whereas in 
> reality people would be availing themselves of well-known 3rd party 
> libraries to do just that.

If one was asking about libraries, one would likely ask that, and not
whether Java has it. I can only repeat what I said above.

Liebe Gruesse,
		Joerg

-- 
Ich lese meine Emails nicht, replies to Email bleiben also leider
ungelesen.

[toc] | [prev] | [next] | [standalone]


Page 1 of 9  [1] 2 3 4 5 6 7 8 9  Next page →

Back to top | Article view | comp.lang.java.programmer


csiph-web