Results 1 to 5 of 5
  1. #1
    pawarkomal is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default Extract data from file and store into separate ArrayList

    Hi,

    I have the following data in my text file.

    A:itl208:20001
    B:itl209:20003

    How do I extract each data and store into separate ArrayList?

    For eg.
    It should extract A,B and store it in ArrayList1.
    It should extract itl208,itl209 and store it in ArrayList2.

    I am new to Java and do not have any programming experience.
    Can anybody help?

  2. #2
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default

    Quote Originally Posted by pawarkomal View Post
    I am new to Java and do not have any programming experience.
    Can anybody help?
    Zero experience ay? I am assuming you know how to make arrays in Java, am I right?

    This question could be really loaded if you do not have "any" experience.

    What do you know?
    java.io.File; ??
    java.util.Scanner;?
    arrays??
    methods and classes?

    YouTube - thenewboston's Channel
    tutorial 78,79 and 80 are on File reading and writing.

    All the tutorials on that page are good.

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    See the API for String (Java Platform SE 6), there are several methods you can use to manipulate strings such as this to pull out the info you want (indexOf, split, etc...)

  4. #4
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Hey Komal,

    Did you get ahead with this?

    Just some pointers, in case if you have not.

    1) Use Scanners to read your file. Read it until next line exists.

    2) Use String split method to split the contents read by scanner using a regex expression for ":"

    3) Use arrays to store the content separated above.

    4) Loop through your array and add each element index wise in your ArrayLists.

    Read the API documentation links provided in case you need any assistance.

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Yeah, people posted some good suggestions - We really need to see what you have so far, and what you have tried already.

Similar Threads

  1. Need a solution to read and store data from a file
    By sheetalnri in forum New To Java
    Replies: 10
    Last Post: 09-30-2010, 06:43 AM
  2. store data into an array from a file
    By chopo1980 in forum New To Java
    Replies: 10
    Last Post: 11-13-2009, 09:48 AM
  3. Replies: 3
    Last Post: 03-28-2009, 05:02 AM
  4. [SOLVED] Extract certain data from file, help
    By battousaibounty in forum New To Java
    Replies: 4
    Last Post: 03-07-2009, 09:16 PM
  5. [SOLVED] How to Extract Data From this text file?
    By jazz2k8 in forum New To Java
    Replies: 31
    Last Post: 04-18-2008, 10:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •