Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Best Method to Write ArrayLists

Best Method to Write ArrayLists

Scheduled Pinned Locked Moved Java
performancequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reagan Conservative
    wrote on last edited by
    #1

    I don't find a suitable method to write ArrayLists to a text file. Does each attribute of the class objects that make up the ArrayList have to be written separately? When I wriye the class object of the ArrayList, it just writes out the memory location. Any advice would be much appreciated. Thank you.

    AF Pilot

    N 1 Reply Last reply
    0
    • R Reagan Conservative

      I don't find a suitable method to write ArrayLists to a text file. Does each attribute of the class objects that make up the ArrayList have to be written separately? When I wriye the class object of the ArrayList, it just writes out the memory location. Any advice would be much appreciated. Thank you.

      AF Pilot

      N Offline
      N Offline
      newbie_
      wrote on last edited by
      #2

      you have to loop through the array list and get each array and print it through loop two for example

      private void printArryList(ArrayList<string[]>someList)
      {
      int counter=0;
      for (int i = 0; i < someList.size(); i++) {
      System.out.print("["+(++counter)+"]");
      for (int j = 0; j < someList.get(i).length; j++) {
      System.out.print(someList.get(i)[j]+" ");
      }
      System.out.println();
      }
      }

      R 1 Reply Last reply
      0
      • N newbie_

        you have to loop through the array list and get each array and print it through loop two for example

        private void printArryList(ArrayList<string[]>someList)
        {
        int counter=0;
        for (int i = 0; i < someList.size(); i++) {
        System.out.print("["+(++counter)+"]");
        for (int j = 0; j < someList.get(i).length; j++) {
        System.out.print(someList.get(i)[j]+" ");
        }
        System.out.println();
        }
        }

        R Offline
        R Offline
        Reagan Conservative
        wrote on last edited by
        #3

        Thank you very much. I couldn't find much about writing out an ArrayList to a file in any of the Java documentation or tutorials (that appeared understandable to me, anyway). Much appreciated.

        AF Pilot

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups