Create an array of vectors

Posted on 2005-04-24
Last Modified: 2008-01-09
Hi everybody,

I'm posting here because I close my previous question ( too quick (the answer helped me understanding my mistake, but now I have a logic problem).

I have a class named Dictionnary with a vectors containing a list of words: "protected Vector mots;"

I created a new class in a different file name "Cruciverbist" which is declared like this: "public class Cruciverbiste extends Dictionnaire"

Now what I want to do is:
- First to declare an array that can contains 24 vectors of words.
- Then, make a constructor that receive a filename of a file containing the list of words.
- Finaly, separate the dictionnary' words depending of their length, putting them in different vectors of the vectors' array.

* There should be a vector for each length of word (2 to 25 letters by word) containing every words of this length.

Here's how I started:

public class Cruciverbist extends Dictionnary
      // First point. How do you declare an array of vectors ? It needs to have 24 elements, but I don't know how to initialize it with these elements...  I need to
           declare a new vector and add empty items ?

      // Constructor.
      public Cruciverbist (String filename) throws IOException
              // I'd like to create a new Dictionnary with the filename passed in parameter.
              // Then I'll have to read each words of the "words" vector and add them in the different vectors of the array.

public class Dictionnary
      protected Vector words;

      // constructor
      public Dictionnary(String filename) throws IOException
            quickSort(words, 0, words.size() - 1);


I would really appreciate if anyone could help me with this one. Thanks

Question by:The_Kingpin08
    LVL 16

    Accepted Solution

    First point:
    private Vector[] words1= new Vector[24];

    In your constructor of Cruciverbist, before you put things in:
    for (int i = 0; i < 24; i++)
        words1[i] = new Vector();

    Second, in your Dictionary class, you need to have a getter for words:
    public Vector getWords() { return words; }

    Third, in your Cruciverbist class, try to use getWords method to get the vector of words.
    Loop for the words vector and check for the length of each element.

    Dictionary d = new Dictionary(filename);
    words = d.getWords();
    for (int i =0; i< words.size(); i++) {
       String word = (String)words.elementAt(i);


    Author Comment

    Thanks a lot pkwan, that looks perfect.

    I still have 2 questions:

    - In my Dictionnary's class constructor, I have a method that automatically fills the vector "words" with all the words from the file. Knowing this, does I still need the
      getWords function ? Because I'd like to keep the dictionnary class as it is if I can. So while creating a new Dictionnary, I thought that a new "words" would be filled
      and ready to used in my new class's constructor... That would give something like this:

      // Cruciverbiste constructor
      public Cruciverbiste (String nom_fichier) throws IOException
            // Initializing the vector's elements
            for (int i = 0; i < 24; i++) arrWords[i] = new Vector();
            Dictionnary d = new Dictionnary (filename);
              // Here we consider that the vector "words" was initialized when we created a new instance of Dictionnary
            for (int i =0; i< words.size(); i++)
                  String word = (String) words.elementAt(i);

    - I'm having an error in my constructor's structure, and I think it's my fault since I never pratice inheritance besides in books...

      >javac Dictionnary(java.lang.String) in Dictionnary cannot be applied to ()
      1 error
      >Exit code: 1
      And here are the line numbers:
      [19]public Cruciverbiste (String nom_fichier) throws IOException

    Thanks for your time, I trully appreciate.
    LVL 16

    Expert Comment

    by:Peter Kwan
    You may be not needing this. You can also delete the Dictionnary d = new Dictionnary (filename);
    as well.

    To solve your problem, you can call


    at the beginning of your constructor of Cruciverbist class

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    Title # Comments Views Activity
    what is spring 3 36
    NotAlone Challenge 20 65
    scoresClump  challenge 31 85
    json example 39 77
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now