Results 1 to 2 of 2
  1. #1
    OldSkoolBray is offline Member
    Join Date
    Apr 2014
    Rep Power

    Default How to index an array so that specific data can be shown

    I am having trouble working out how to index the arrays so that i can choose specific data so that averages and maximum and minimum values can be worked out. My code is below ...... any help would be much appreciated thanks .

    package weatherProgramPackage;

    import java.util.ArrayList;

    public class Class1 {

    public static void main(String[] args) throws IOException {

    // variables
    String line;
    String [] parts;

    // apply array lists to hold string information of columns (titles) for later use
    // in identification (assigning to values of i)
    ArrayList<String> year = new ArrayList<String>();
    ArrayList<String> month = new ArrayList<String>();
    ArrayList<String> maxTemp = new ArrayList<String>();
    ArrayList<String> minTemp = new ArrayList<String>();
    ArrayList<String> afdays = new ArrayList<String>();
    ArrayList<String> rainmm = new ArrayList<String>();
    ArrayList<String> sunhrs = new ArrayList<String>();

    // set up a new file input
    BufferedReader file = new BufferedReader(new FileReader("sheffielddata.csv"));

    // while there is still more to read
    while((line = file.readLine()) != null) {
    //splits line into parts
    parts = line.split(",");
    // apply for loop to add selected data according
    // to index (i and associated values), thus producing rows
    // from excel with elements identified by column (title)
    for (int i = 0; i < parts.length; i = i + 7)
    //this adds up the identified parts into string arrays;
    month.add(parts[i + 1]);
    maxTemp.add(parts[i + 2]);
    minTemp.add(parts[i + 3]);
    afdays.add(parts[i + 4]);
    rainmm.add(parts[i + 5]);
    sunhrs.add(parts[i + 6]);

    ArrayList<String> partsTotal=new ArrayList<String>();
    partsTotal.add(parts[i + 1]);
    partsTotal.add(parts[i + 2]);
    partsTotal.add(parts[i + 3]);
    partsTotal.add(parts[i + 4]);
    partsTotal.add(parts[i + 5]);
    partsTotal.add(parts[i + 6]);

    String partstot[] = partsTotal.toArray(new String[partsTotal.size()]);

    for (String k: partstot)



  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: How to index an array so that specific data can be shown

    Please place [code][/code] tags around your code to properly format it. Can you also provide
    more explanation with some examples because I am still not certain what you are asking for.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 1
    Last Post: 04-11-2014, 02:39 AM
  2. Replies: 5
    Last Post: 01-07-2013, 10:10 PM
  3. Feedback form of specific data,...
    By danpotter in forum JDBC
    Replies: 10
    Last Post: 01-01-2013, 02:22 PM
  4. Adding an item to arrayList at a specific index
    By randoms:) in forum New To Java
    Replies: 2
    Last Post: 05-11-2011, 04:25 PM
  5. How to check if a specific data in a collum
    By mike_ledis in forum JDBC
    Replies: 0
    Last Post: 04-27-2011, 02:09 PM

Posting Permissions

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