arraylist problems?

Ads
 

arraylist problems?

myprogram needs to ask the user for a file name. The file will contain a name on each line. Put each of the names into an ArrayList.

After you have put all of the names into the ArrayList search through the list and print out the following information;

Print out the longest name
Print out the shortest name
print out the total number of characters in all of the names.
print out the average number of characters per name
print out the whole list after the previous four pieces of information.

i have this so far. help with at least one aspect?

import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Scanner;

public class project1 {

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

          String filename = "";
          String longestString ="";
          int i;

          ArrayList<String> filestrings = new ArrayList<String>();

          Scanner keyboard = new Scanner(System.in);

          System.out.print("Enter the name of the file you would like to search:");
          filename = keyboard.nextLine();


          File file = new File(filename);

          if (!file.exists())
          {
          System.out.println("The file " +filename+ " is not found.");
          System.exit(0);
          }


          else
          {
              System.out.println(file);
          }

          File file1 = new File(filename);
          Scanner inputFile = new Scanner(file);

          while (inputFile.hasNext())
          {

          String line = inputFile.nextLine();
          filestrings.add(line);
          }
          System.out.println("There are " + filestrings.size() + " words in this document.");




       }
}
View Answers

Ads









Related Tutorials/Questions & Answers:
arraylist
ArrayList
Advertisements
arraylist
arraylist
arraylist
arraylist
arraylist of an arraylist
arraylist in java
ArrayList object
ArrayList elements
comparing arraylist of an multi dimensional arraylist
accessor arrayList
ArrayList in java
ArrayList programe
Cannot assign an ArrayList to an empty ArrayList
vector and arraylist
arraylist problems?
java arraylist
ArrayList
arraylist
arrayList
Remove multiple elements in arraylist
ArrayList as an argument to another class
How to Convert ArrayList to Array?
Java ArrayList Example
Can ArrayList accept an ImageIcon >>????
Diff between ArrayList and Vector?
assigning arraylist to combo box
Core Java-ArrayList
Two - dimension arraylist
to use ArrayList in the place of Vector

Ads