Adding two array lists together and a text file to an array list

I'm having problems coding these two methods... Could someone explain how to do this? I can't find information on it anywhere... :(
"MagazineList" is the class I'm coding in right now, and I already declared "list" as an array list of another class called "Magazine".
public boolean addAll(MagazineList magazines)
       if (list == magazines) {
           return false;
        else {
            list.addAll(magazines);
       return true;
   public boolean addAll(String filename)
       Scanner in = ResourceUtil.openFileScanner(filename);
        if (in == null) {
           return false;
        String line = source.nextLine();
        while (!line.equals("")) {
          list.add(Magazine(source));
       in.close();
   }

I assume "addAll(MagazineList magazines)" is defined in the MagazineList class?
Then,
list.addAll(magazines);probably needs to be something like:
list.addAll(magazines.list);This uses the private variable ( should be private) list from the input MagazineList, and adds all of those Magazine objects to the list in the current MagazineList.
But, yes, describe your problems more clearly, and you'll get better answers more quickly (because people will be able to understand you and give you a suggestion without asking you another question first).

Similar Messages

  • I just added two external firewire drives and they keep going to sleep.  I did not have this problem when USB.  I have turned off "put disks to sleep" in power preference.

    I just added two external firewire drives and they keep going to sleep.  I did not have this problem when using USB external drives.  I have turned off "put disks to sleep" in power preference.

    It is not clear if these are the same drives, just connected
    differently, or different drives?
    One thing that may be happening is that the drives firmware
    itself is putting it to sleep when inactive.  Many drives on
    the market have ths feature and it is turned on by default
    and require a drive utility from the manufacturer to disable it.

  • Converting a text file into an array

    import java.io.*;
    public class Copy {
    public static void main(String[] args) throws IOException {
         File inputFile = new File("farrago.txt");
         File outputFile = new File("outagain.txt");
    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    int c;
    while ((c = in.read()) != -1)
    out.write(c);
    in.close();
    out.close();
    i have been working my way through the online tutorials and have found them very helpful, i have looked at array and would like to know how to convert data from a text file inot an array? using the above example how would i go about doing this?

    You'd use the readLine () method:BufferedReader reader = new BufferedReader (new FileReader (file));
    String line;
    List list = new LinkedList ();
    while ((line = reader.readLine ()) != null) {
        list.add (line);
    // don't know why you'd want this, but anyway
    String[] lines = (String[]) list.toArray (new String[list.size ()]);Kind regards,
      Levi

  • Reading one line from a text file into an array

    i want to read one line from a text file into an array, and then the next line into a different array. both arays are type string...i have this:
    public static void readAndProcessData(FileInputStream stream){
         InputStreamReader iStrReader = new InputStreamReader (stream);
         BufferedReader reader = new BufferedReader (iStrReader);
         String line = "";          
         try{
         int i = 0;
              while (line != null){                 
                   names[i] = reader.readLine();
                   score[i] = reader.readLine();
                   line = reader.readLine();
                   i++;                
              }catch (IOException e){
              System.out.println("Error in file access");
    this section calls it:
    try{                         
         FileInputStream stream = new FileInputStream("ISU.txt");
              HighScore.readAndProcessData(stream);
              stream.close();
              names = HighScore.getNames();
              scores = HighScore.getScores();
         }catch(IOException e){
              System.out.println("Error in accessing file." + e.toString());
    it gives me an array index out of bounds error

    oh wait I see it when I looked at the original quote.
    They array you made called names or the other one is prob too small for the amount of names that you have in the file. Hence as I increases it eventually goes out of bounds of the array so you should probably resize the array if that happens.

  • Read and write from and to text file

     Hi All,
    I am trying to read some portion of a text file and make measurement and calculation with those numbers and write back to the same text file and also to a excel file. I need to create a 2 D  array of 20 by 20 from the text file values and write to front panel table and to text file. but I am having problem with it, obviously I am new to this. Please help me.  thanks much
    ~ Johnny

    Hi Lynn,
    the requirement is to move C1 and C2 to each position that is given in the text file in steps and percentage value.
    for example C1 has to go to first step (5%) and C2 has to go thru all steps, 5% to 95% , in 5 percent increment. 
    each 100 steps translates to 1 percent increment in the capacitor value.
    at the end, I need to enter the measured data (values of C1 for each step, vesus all values of C2 for all steps) and enter them at the bottom of the text file's table where it starts at : "IMPEDANCE_REAL in Ohmone line per C1 position, containing all values for the different C2 positions" and do the same for where it says "IMPEDANCE_IMAGINARY in Ohmone line per C1 position, containing all values for the different C2 positions"
    the reason I read the file twice, is that if it read it once, I couldn't connect it to spreadsheet string to array vi.
    as you can see, I also like to use the write to measurement file and build table express vi's to display the table on the front panel and save the data to ni data file format so later I convert it to excel  too.
    any thoughts?
    thanks for your help
    ~ Johnny
    Attachments:
    read from text2.vi ‏82 KB

  • How can u insert and retrieve text files in any format using forms6i.

    how can u insert and retrieve text files in any format using forms6i.
    can u give me an example of an insert statement, let's assume the file is located in the a:drive.
    and retrieving the files, i would give the user a list of all the files that are in the database, the user would select one, but what command(or piece of code) would open the file in its apppropriate editor.
    e.g .pdf formatted file would open in acrobat.
    any help would be appreciated.
    Thanks
    Hussein Saiger

    the filereference class is for downloading and uploading files.
    if you want to load xml, use the xml class.
    and, if you want to write to an xml file and don't want to use server-side code, wait.

  • What is the best method for writing Multicolum​n List data to a text file?

    I am trying to find the best method for writing the data from a multicolumn list to a text file. Say the list has 7 rows and 6 columns of data. I would like the final file to have the data resemble the Multicolumn List as closely as possible with or without column headers. A sample VI showing how to accomplish this would be greatly appreciated. I realize this is pretty basic stuff, but I can get the output to the file, but it comes out with duplicate data and I am on a time crunch hense my request for help.
    Thank You,
    Charlie
    Everything is Free! Until you have to pay for it.

    Hello,
    I think that the answer to your question it's on the example that I've made right now.
    See the attached files....
    Software developer
    www.mcm-electronics.com
    PS: Don't forget to rate a good anwser ; )
    Currently using Labview 2011
    PORTUGAL
    Attachments:
    Multi.vi ‏12 KB
    Multi.PNG ‏6 KB

  • How to create and read text file using LabVIEW 7.1 PDA module?

    How to create and read text file using LabVIEW 7.1 PDA module? I can not create a text file and read it.
    I attach my code here.
    Attachments:
    File_IO.vi ‏82 KB

    Well my acquisition code runs perfect. The problem is reading it. I can't seem to read my data no matter what I do. My data gets saved as a string using the array to string vi but I've read that the string to array vi (which I need to convert back to array to read my data) does not work on the pda. I'm using version 8.0. So I was trying to modify the program posted in this discussion so that it would save data from my DAQ. I did that but I still can't read the data after its saved. I really don't know what else to do. All I need to do is read the data on the pda itself. I can't understand why I'm having such a hard time doing that. I found a possible solution on another discussion that talks about parsing the strings because of the bug in the "string to array" vi. However, that lead me to another problem because for some reason, the array indicators or graphs don't function on the pda. When i build the program to the pda or emulator, the array indicators are faded out on the front panel as if the function is not valid. Does this kind of help give a better picture of what I'm trying to do. Simply read data back. Thanks.

  • How to write from a linked list collection to a text file.

    Hi,
    I want to write my data in linked list collection to a text file.
    the following is the code of my linked list. how do i write it
    Iwant the data to be comma separated while writing it to a text file.
    please help.
    class MailList
            public static void main(String args[])
                    LinkedList m1 = new LinkedList();
                    m1.add(new Address("J.W.West", "11 Oak Ave",
                           "Urbana", "IL", "118011"));
                    m1.add(new Address("H.S.sandy", "1 k ve",
                           "Bana", "L", "18011"));
                    m1.add(new Address("K.Satish", "1 104 Clarence Street",
                            "Strathfield", "NSW", "135"));
                    Collections.sort(m1);
                    Iterator itr = m1.iterator();
                    while(itr.hasNext())
                            Object element = itr.next();
                            System.out.println(element + "\n");
    }

    look at the API for FileWriter.
    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • Can I save and read text files on a server that I host?

    Hello everyone,
    I am a java hobbiest. I was wondering if I set up my own server, running out of my house, could I have my applets save to my computer and read from my computer without having to learn JDBC and a DATABASE language. In other words could i just have my applet save and read text files from and to my server?
    I'm trying to set up a sight for my 5th grade class where parents can log into. Thanks for your time.
    Oh yeah, which is easier, learning how to set up a server or learning JDBC and a DATABASE language?
    If you have any other good idease please tell me them
    Thank you, Bryan

    Short answer: This isn't gonna work
    Long answer: For this to work, the first thing you're going to need is a static IP address and a DNS name registered -actually you don't necessarily need #2 but you're probably gonna want it and it's by far the easier of the steps.
    As far as I know to get a fixed IP address you've either gotta be directly attached to a larger network (ie university network) or get a leased line from an ISP.
    Once you've got that done come back to us.

  • SoD Risk Summary and Rule Text Files for CC 5.1

    Hi,
    Could anyone share with me where could I find the SoD Risk Summary and Rule Text Files for CC 5.1? I have looked into SAP Marketplace but I was not able to find such information. In the installation files we downloaded, these files are not included either
    Thanks in advance. Regards,
        Imanol

    Hi,
    These rules were available on the market place for CC 40: they were included in the support package 1 or 2.
    For CC 51, we had the same issue as you: we did not find the rules on the market place. Apparently, they are not.
    My customer had to send a OSS message to SAP in order to receive the rules (.txt files).
    Regards,
    Nicolas.

  • Query SQL and output to text file then loop through list to execute

    It seems there's no obvious way to do what I want to below as everyone has their own take on querying SQL server with Powershell!
    I need to use PowerShell to connect to ServerA and query a test database and select Name from it.  The Name results of that query need to output to C:\names.txt and then I need a ForEach loop to go through that file line by line and execute some text
    against each Name from the list.
    Any ideas how I can achieve this?
    Thanks!

    I can't even output SQl to a table at the moment, the text file has a column header and about 50 empty rows in the file.
    $dataSource = "DEMO"
    $database = "TESTDB"
    $connectionString = "Server=$dataSource;uid=$user; pwd=$pwd;Database=$database;Integrated Security=True;"
    $query = "SELECT name FROM dbo.names"
    $connection = New-Object System.Data.SqlClient.SqlConnection
    $connection.ConnectionString = $connectionString
    $connection.Open()
    $command = $connection.CreateCommand()
    $command.CommandText  = $query
    $result = $command.ExecuteReader()
    $table = new-object "System.Data.DataTable"
    $table.Load($result)
    $format = @{Expression={$_.Id};Label="Name";width=25}
    $table | format-table $format | Out-File C:\export\servers.txt
    $connection.Close()

  • Adding two time figures together

    Please forgive me I am not familiar with FormCalc or Javascript.
    I am creating a form for work and I need to add two time figures minutes and seconds (IE 02:30 + 02:30) I have looked all over the web and I can not find anything that is working,
    I can add the two figures together but I get (ie 4:60)
    please any help you can give will be be wonderful

    Hi Chris,
    No need to shout.
    Formula in column C (calculates the Duration (time elapsed) between two Date and Time values:
    =B-A
    Formula in column D (Calculates the same Duration as above, but subtracts 30 minutes if the total Duration is greater than 5 hours):
    =IF(DUR2HOURS(B-A)>5,B-A-DURATION(,,,30,,),B-A)
    Note that any cell displaying a Date or a Time (of day) or both contains a Date and Time value.
    If only the Date has been entered, the time part is set to 00:00:00 (midnight, at the beginning of that day).
    If only the Time has been entered, the date part is set to the date the entry was made.
    In the table above, the values in Row 18, the bottom row of the table are as follows:
    A18: March 1, 2012 11:00:00 AM
    B18: March 1, 2012 5:00:00 PM
    C18: 6h
    D18: 5h 30m
    The first two are Date and Time values, the second two are Duration values.
    Regards,
    Barry

  • Passing lines in a text file to an array

    Hi,
    I did a search on this, looked through the tutorials. I want to read in a line from a text file and pass it to an array. here's my code:
    package pack1;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.util.Scanner;
    public class CDSort {
          * write a program that will read a bunch of cd's from a textfile,
          * count how many there are, and figure out how many cd boxes I will need based
          * on a fixed amount that will fit in each box. The cd's should be sorted alphabetically,
          * and each should be placed in a numbered box, and have a numbered position within that box
         public static void main(String[] args)throws Exception {
              java.io.File cdlist = new java.io.File("files/cd-list.txt");
              FileReader infile = new FileReader(cdlist);
              FileWriter outfile = new FileWriter("files/newlist.txt");
              if (cdlist.exists()){
                   System.out.println( cdlist.getName() + " exists at " + cdlist.getAbsolutePath());
                   System.out.println("this file was last modified on: " + new java.util.Date(cdlist.lastModified()));
                   int c;
                   while ((c = infile.read()) != -1) {
                        System.out.println(c);
                        String [] textArray = new String[99];
                             for(int i =0; i<textArray.length; i++){
                                  // trying to pass text to array here: I tried this, but got an error:
                                  //textArray[i] = infile.read(c);
                                  // i added this statement so I could see what the value of the array was on the console
                                  System.out.println(textArray[i] + i);
                        outfile.write(c);
                   infile.close();
                   outfile.close();
              } else
                   System.exit(0);
    }This is probably a pretty basic question, but my hunting arround hasn't really yielded anything.

    okay, here's what I did, this seems to work.
    package pack1;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.PrintStream;
    public class CDSort {
          * write a program that will read a bunch of cd's from a textfile,
          * count how many there are, and figure out how many cd boxes I will need based
          * on a fixed amount that will fit in each box. The cd's should be sorted alphabetically,
          * and each should be placed in a numbered box, and have a numbered position within that box
         public static void main(String[] args)throws Exception {
              java.io.File cdlist = new java.io.File("cd-list.txt");
              FileReader infile = new FileReader(cdlist);
              //FileWriter outfile = new FileWriter("newlist.txt");
              BufferedReader br = new BufferedReader(infile);
              BufferedWriter out = new BufferedWriter(new FileWriter("newlist.txt"));
              if (cdlist.exists()){
                   System.out.println( cdlist.getName() + " exists at " + cdlist.getAbsolutePath());
                   System.out.println("this file was last modified on: " + new java.util.Date(cdlist.lastModified()));
                   // while loop was here, I removed it.
                   String [] textArray = new String[99];
                   String line;
                   int lineNum = 0;
                   while ((line = br.readLine()) != null){
                        textArray[lineNum++] = line;
                        System.out.println(line);
                   int numOfCds = 1;
                   int boxNum = 1;
                   int boxPos = 1;
                   int cdsPerBox = 20;
                   out.write("Contents of Box " + boxNum);
                   out.newLine();
                   out.newLine();
                   for(int i = 0; i<textArray.length; i++){
                        out.write(textArray[i] + " box position: " + boxPos + "\n");
                        out.newLine();
                        boxPos++;
                        numOfCds++;
                        if (boxPos >= cdsPerBox){
                             boxNum++;
                             out.newLine();
                             out.newLine();
                             out.write("Contents of Box " + boxNum);
                             out.newLine();
                             out.newLine();
                             boxPos = 1;
                   infile.close();
                   out.close();
              } else {
                   System.out.println("file not found, program terminating");
                   System.exit(0);
    }thanks for all your help.
    bp

  • How to find the ocuurence of a word from LIST A in LIST B in a text file?

    Hey if you look at the text file there is LIST A and LIST B.. i need to find the ocuurence of a word from LIST A in LIST B. Eg: if my output is (1,3)
    then first word from LIST A occurs in 3 places in LIST B.
    Can you please get the sample code to do this process.
    Please let me know..
    My text file looks like this below :
    phrases.txt
    LIST A
    aamsz
    abaffiliate
    aboard casino
    above computer
    above pop
    above violat
    LIST B
    http://209.153.231.131
    HTTP/1.0 200 OK
    Server: Microsoft-IIS/5.0
    Date: Mon, 02 Feb 2004 11:53:26 GMT
    IISExport: This web site was exported using IIS Export v2.2
    IISExport: This web site was exported using IIS Export v2.2
    Content-Length: 274
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDSSDBBBAR=OOGFKOJBMKMDCGPIHPADALHB; path=/
    aboard casino
    Cache-control: private
    abaffiliate
    above computer

    The key difference is that Vector is synchronized whilst ArrayList is not. Synchronized means that the classes methods can safely be accessed by different threads and as your application will not be multithreaded then the ArrayList is possibly the better option.
    To store Strings in an ArrayList, you first need to declare the ArrayList object something like this;
    ArrayList<String> listAList = new ArrayList<String>();and you would obviously do something similar for the ArrayList that will hold the Strings that should belong to List B.
    The first thing to note is that you can use the new (well new in version 1.5 anyway) generics techniques to specify the type of the object the ArrayList will hold; Strings in this case.
    To add a value into the ArrayList once you have read it from the file and decided if it belongs in the List A or List B ArrayList, all you need to do is call the add() method of the ArrayList something like this;
    // Assume that you read the line from the file into a variable called temp;
    listAList.add(temp);To compare the two lists, the easiest option would be to iterate through one ArrayList and ceheck to see if the values you recover from it are duplicated in the other ArrayList. Luckilly, ArrayList has another method that helps here, it is called contains();
    Assuming that you have two ArrayList(s), one called listAList that holds the Strings that belong to List A and another called listBList that holds the Strings that belong to ListB, you could do something like this to check for duplicates;
    for(String element : listAList) {
        if(listBList.contains(element)) {
            System.out.println("Found a match");
    }Hope that helps.

Maybe you are looking for