arraylist problems?

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









Related Tutorials/Questions & Answers:
arraylist
ArrayList
Advertisements
arraylist
arraylist
arraylist
arraylist
arraylist of an arraylist
arraylist and vector
Java ArrayList
ArrayList and Vector
arraylist in java
ArrayList object
ArrayList elements
Java arraylist of arraylist
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
Java arraylist, linkedlist
Remove multiple elements in arraylist
ArrayList as an argument to another class
How to Convert ArrayList to Array?
Java ArrayList Example
Printing ArrayList - JSP-Servlet
Can ArrayList accept an ImageIcon >>????
arraylist with session - JSP-Servlet
Core Java-ArrayList
Diff between ArrayList and Vector?
assigning arraylist to combo box
Two - dimension arraylist
to use ArrayList in the place of Vector
to use ArrayList in the place of Vector
ArrayList - JSP-Interview Questions
ARRAYLIST CODE - Java Beginners
Collection : ArrayList Example
Convert ArrayList to Array
Convert Array to ArrayList
ArrayList problem - JSP-Servlet
set the arraylist values - Struts
arraylist - Java Beginners
Unexpected Behaviour of ArrayList
arraylist problem - Java Beginners
arrayList - Java Beginners

Ads