javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yes, as long as it is an integer, or it can be parsed to one.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
for (int i = 0; i < adj2.length; i++) {
				for (int j = 0; j < adj2.length; j++) {
					path += [B]adj[i][j]*adj[j][i][/B];
}
}

The above always returns 0. If you run the code by hand you will see that the above snippet, never has 2 elements that this happens: 1*1 . Try a different initial array.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No, args[0] is not null. The array args has length 0. So the args[0] gives you the exception since there is no '0' element; the length of the array is 0.
The elements of the args will never be null .
Depending on the number of parameters you pass the array args will be created with those parameters. So if you pass 2 parameters, the args will have length 2. args[0], args[1] will have those values.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public class ArithmeticOperatorImpl implements ArithmeticOperator {
  ....
}
public class OpIterator implements OperatorIterator {
  ....
}

Then create the OperatorFactory class that creates ArithmeticOperatorImpl objects and returns them based on the input

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have a login page. How else will you be able to distinguish them apart. There is a tutorial in this forum

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

According to the output you wanted, I made something very simple, I don't know if that's what you wanted...

import java.util.Scanner;

public class quiz
{
	public static void main(String []arg)
	{
		Scanner input = new Scanner(System.in);
		int x, y, z;
		
		System.out.print("Enter your name: ");
		String name = input.next();
		System.out.print("How many quizes do you want: ");
		String quiz = input.next();
		
		System.out.print("\nQuiz-1: ");
		int quiz1 = input.nextInt();
		System.out.print("Quiz-2: ");
		int quiz2 = input.nextInt();
		System.out.print("Quiz-3: ");
		int quiz3 = input.nextInt();
		System.out.print("Quiz-4: ");
		int quiz4 = input.nextInt();
		System.out.print("Quiz-5: ");
		int quiz5 = input.nextInt();
		
		int total = quiz1 + quiz2 + quiz3 + quiz4 + quiz5;
		
		System.out.println("Total Score: " +total);
		System.out.println("Average: " +(double)(total/10));
		
		
	}
}

Totally wrong, not to mention that we don't give away free homework.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

java.lang.NumberFormatException: For input string: "None"

Doesn't this give you a clue?
You are trying to convert the "None" into a number, probably with Integer.parseInt(...)

Whenever you call this: Integer.parseInt(...) you need to have a try-catch in order to handle the error if it is not a number.

The errors that you get should tell you at what line it occurred.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Assuming that the sentence is stored in a String variable, why don't you check the String API. We might find something there that could be useful.


PS. I didn't notice that this is my 1666 post!

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

None of your codes are correct. As stated in your previous thread by me, your initial code was correct. But it seems that you followed an incorrect suggestion by another member. The new line character should be placed outside the inner loop:

String r  = "";
         for(int i =1; i <= rows; i++)
                {
                        for(int j = 1; j <=columns; j++)
                            {
                             r = r + " _";
                             //[B]r = r + "\n";[/B]
                            }
                            [B]r = r + "\n";[/B]
                         // [B]return r;[/B]
                 }
[B]return r;[/B]

And of course the return must be at the end of your program, outside the outer loop. With your code, you return the moment the inner loop finishes the first time and the outer loop doesn't get a chance to finish.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

My apologies, but please take note to the fact that i said that i believe his code should look like this. the way i was taught for loops says that you should include brackets to enclose the body of the loop otherwise it will not function correctly. my apologies for trying to help.

TJ

Then this would be correct:

for(int i = 1; i <= rows; i++)
                {
                        for(int j = 1; j <=columns; j++) {
                                r = r + " _";
                        }
                        r   = r + "\n";      
                }

Your error was a logical one, the code would compile but not do what it is suppose to do. You were taught to use brackets but be careful where you put them.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Manual. Gives full control with no "bolierplate", repetitive, rigid code.

But that's not what you're looking for is it? I dislike all "Gui builders", as they all produce rigid, reptitive code that is hard to modify correctly, and is not always that effecient when any action to be performed is more than popping up a dialog.

I agree. I prefer to write my own gui.

Surely I also use a Gui Builder but just to quickly declare and place the elements.

But most of the times I do them on my own.
It is hard to use a gui builder to create dynamically a list of buttons or a ComboBox whose values are generated by some other function.

It is better to learn how to create JFrames on your own and not depend on a builder. Especially for actionListeners. The code that they generate is not easy to follow and you won't learn how they work and called.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
for(int i = 1; i <= rows; i++)
                {
                        for(int j = 1; j <=columns; j++)
                        r = r + " _";
                        r   = r + "\n";            
                }

Your nested "if" statement's statements are not defined correctly, and/or your indenting is problematic. I BELIEVE your code should look like this:

for(int i = 1; i <= rows; i++)
                {
                        for(int j = 1; j <=columns; j++) {
                                r = r + " _";
                                r   = r + "\n";      
                        }
                }

You couldn't be more wrong.


>>>>> Shotty, your code is correct.


And tjsail try running what you wrote and what Shotty wrote and see the difference. Don't give wrong advices without testing them or running the poster's code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You haven't described what is your problem and what have you done so far. Don't expect us to read the entire code and see what works and what doesn't.
Also you are mixing everything up.

Forget about the gui.
Keep the node class and create an AVLTree class. The Tree is not a gui and has nothing to do with is. It is a tree. Meaning, test the functionality of the tree separately. The tree will do only the things you described. Have methods with arguments that search and delete and test all of them using System.out.print in a separate class. That class will have only the main method. Instantiate the tree in the main method and test it. Then create another gui class and this time instantiate the tree in there and use its methods.

That way if something doesn't work you will know what it is.

With your description and code no one is going to understand what is your problem. If your problem is for example "preorder" then all you have to do is fix the specific method and test it separately in the main method that I described. If it works, in the same main you will test the rest of the methods.
Then if all of them work you will call the Tree class in the new gui class that you will create and all other errors that you will be getting will be gui related. So you will …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I run your code and as you can see it outputs correctly:

public static String toString2(float [] number) {
        String formatStr = ">%6d %16.2f";
        String outString = "";
        for (int i = 0; i < number.length; i++) {
            String result = String.format(formatStr, i, number[i]);
            outString = outString + result + "\n";
        }
        return outString;
    }


    public static void main(String [] args) {
        float [] num = new float[12];
        System.out.println(toString2(num));
    }

The problem might be with the way the TextArea renders the results.
Have you tried displaying only the toString method at the JTextArea? As you can see above, if you run the example, it displays at the console the format that you want

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Use a for loop, to loop through the ArrayList and print its elements instead of the System.out.println(row1)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all, line will never be null so you don't need to check that. By doing this: while (scan.hasNext()) { ... You make sure that there is a next line in the file.

Also what java version are you using because the contains method was added at 1.5. I was about to tell that this was the mistake because I was looking the wrong API version.

So what is the value of the "s" variable.
Why don't you just do this: s = "a"; Also if you want the existence of "a" for example don't use contains because it will return false for any word that has the letter "a".
Use line.equalsIgnoreCase(s) And you need to post the errors that you are getting if any, and some sample input and output. Try a small file at first that you can check.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In your class the "s" input is the one that has the values not the Score. I mean it is the "s" that you pass as parameter, then you put values from s to Score. Why on earth are you checking the values of Score if you put the values "s" in it after the checking?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is an array of doubles and I am not getting any errors, it works just fine in all the ways I have posted. It just isn't formatting properly.
This is how it is currently outputting

1      0.00
  2      0.00
  3      0.00
  4      0.00
  5      0.00
  6      0.00
  7      0.00
  8      0.00
  9      0.00
  10      0.00
  11      0.00

this is how I want it to output

1      0.00
 2      0.00
 3      0.00
 4      0.00
 5      0.00
 6      0.00
 7      0.00
 8      0.00
 9      0.00
10      0.00
11      0.00

ignore the black numbers to the left of the red numbers

Well I believe that it's time to show your code. And probably the error is that your array is empty, you didn't put any values in it. And if you did at some point in your program, then you are not passing the array that has values in it.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

cart is supposed to be an array. Am I doing arrays properly? I can't find very much documentation on arrays.

And one more clarification. You might already know, and I might look silly telling it to you it is very important and lots of people do that mistake:

cart is supposed to be an array.

cart is not an array. cart is an int. cart is an array.

Meaning that cart should be treated like an array. You can call the methods of an array like .length.
But cart is an int and can be used in any other way you could use an int:

void method(int arg) {

}

method(cart[i]);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster


The format String would be like a way of saying how the arguments will be printed. String formatStr = "I: %6[B]d[/B], Value: %16[B]d[/B]"; The %6d, %16d will be replaced by the arguments of the
....

Is the number[] an array of ints or an array of floats ?
And it would be helpful if you posted the errors that you are getting.

Your code works for me only if the array is an array of floats. I believe that the API has a list that says when to use what ("%f or %d")

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is a bit late for answering but I am surprised that no one mentioned anything like Gundam Zeta or Yamato. Well if you want to hear it from someone who has seen a lot then here it is:

Series:
Yamato Season 2 (Unfortunately in the US known as Starblazers)
Neon Genesis Evangellion
Death Note
Robotech: The Macross Saga.

Movies:
Lock the Superman
Nausicca and the Valley of the Winds
Vampire Hunter D : Bloodlust.
Perfect Blue

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Ooh, ooh, how come I didn't notice this thread? Anyways, try guessing this for starters; simple of course:

Is your avatar from an anime? If yes from what?

Also guess this:
His is very short, hates milk, doesn't need to draw circles and absolutely hates being called short.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

PS: Members, please do not point obvious resource.

And I was wondering why, especially you, didn't point him to that obvious resource. :)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all the format String must not change. It is the one the determines how the output will be formatted:

outString = String.format(outString,%6d,%16f,i,numArray[i],"\n")
 
//or

outString = outString+String.format(%6d,%16f,i,numArray[i])+"\n";

After the first loop you change the outString so the rest of the results will be all over the place.
You need to store the result into another String:

String formatStr = "....";

// from the API:
String result = String.format(formatStr, [B][U]arguments[/U][/B]);

The format String would be like a way of saying how the arguments will be printed. String formatStr = "I: %6d, Value: %16d"; The %6d, %16d will be replaced by the arguments of the String.format method: String result = String.format(formatStr,[B][U]i,numArray[i][/U][/B]); You don't need the "\n". If you want a new line just use System.out.println.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all this: musicArray[count] = music; count++; Can go outside the if statements. I mean in all the ifs you do the same. It doesn't matter what type of Music it is you are still going to put it in the array, so you can have it outside. You repeat the above in all of your ifs. And what will happen if the music is of type Music. You don't have such if statement.


Here is an example on how you can make the code better:

public class Music implements Serializable {
    public [B]Music[/B]() {
    }
    
    public String [B]toString[/B]() {
        return "This class is of type: "+this.getClass().getName();
    }
    
    public void [B]print[/B]() {
        System.out.println("This is a [B]Music[/B].");
    }
}
public class [B]ClassicalPiece [/B]extends Music {
    public ClassicalPiece() {
    }
    
    public void [B]print[/B]() {
        System.out.println("This is a [B]ClassicalPiece[/B].");
    }
}
public class [B]RockSong [/B]extends Music {
    public RockSong() {
    }
    
    public void [B]print[/B]() {
        System.out.println("This is a [B]RockSong[/B].");
    }
}

As you can see they all have the "print" method:

public static void main(String[] args) {
        Music [] array = new Music[3];

        array[0] = new RockSong();
        array[1] = new ClassicalPiece();
        array[2] = new Music();

        // array[i] are Music type.

        for (int i=0;i<array.length;i++) {
            array[i].print();
        }
    }

array are Music type. So you would assume since the print method of the Music class is called this would be the result:

This is a Music.
This is a Music.
This is a Music.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

From the original array count how many people there are for each personality type and have those values be in 4 variables. Use those 4 variables to create 4 arrays and then loop again in order to populate them.

As for the rest we will not give it another thought unless we see some code for the first.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You forgot to use code tags

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Start a new thread. Use code tags

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You said I do not need casting but I am having trouble putting the subclass object variables into the musicArray. I read last night that this is because I have to upcast to the parent object.

I ran this:

Music [] array = new Music[3]; // array is an array and it is not null

        // Its elements are so you need to initalize them
        array[0] = new RockSong();
        array[1] = new ClassicalPiece();
        array[2] = new Music();
        // array[0], array[1], array[2] are Music

        for (int i=0;i<array.length;i++) {
           System.out.println(array[i]);
        }

And it worked.
For the other way around you need "down casting", after checking of course if it can be done with the "instanceof"

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I know the "need to ask the user the name of the friend you want to delete, then search the list to find where that friend is and then remove it" I don't know how to do that part...

"need to ask the user the name of the friend you want to delete"; // use the Scanner class
String name;

"then search the list to find where that friend is" // use a for loop
int index;

"then remove it" // search the ArrayList API

And it is better to start by creating a Friend class; start by doing one thing at the time.
First try to keep adding friends to the list and have another option that just displays them(no sorting for starters). When you are done with that, move on with the rest.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
boolean b = true;

do {
  ....
  //do something with the b variable
  ....
} while (b);

The loop will terminate when the answer is found.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all learn the difference between PreparedStatements and Statements.

You initialize the prepareStatement with a fixed query (wrong) and then you call this: pstmt.setString(1, Cust_Id); ????
You don't have an argument at index 1 at the query. Where the (1, Cust_Id) will be applied????

And if we assume that you keep your query the way it is and you don't assign a parameter since you already have one: Cust_Id = '" + Cust_Id + " '" Did you notice the space at the last set of quotes: Cust_Id = '" + Cust_Id + [B]"[/B] '[B]"[/B] PS. The question marks at the first part of the post aren't there for fun. They are a hint.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Edit: Sorry for the mistake post. I didn't see the names of the posters.


Also, sheehab posting just the code will not do you any good. You need to explain what it does in general, what it is supposed to do, how it behaves now, what errors do you get and at what line.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't add friends here:

System.out.println("Enter a friend by their first name"); 
        firstName = input.nextLine(); 
        [B]friendList.add(firstName); [/B]
        System.out.println("Enter a friend by their last name: "); 
        lastName = input.nextLine(); 
        [B]friendList.add(lastName); [/B]
        System.out.println("Enter their telephone number: "); 
        telephone = input.nextLine();
        [B]telephoneList.add(telephone);[/B]

You simply add the info of one friend. How on earth are you going to read that from the list?

Create a Friend class/object, and when you read from the keyboard instantiate such an object and put that inside. Also for the delete you need to ask the user the name of the friend you want to delete, then search the list to find where that friend is and then remove it. Look the API for the ArrayList. With your way you remove the element that has the same value as the last value entered to the 'lastname' variable: friendList.remove(lastName);

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I started this post after you added your second post. The extended class seems fine. What is the problem with driver. Just instantiate it and call its methods.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The thread has already been answered and apparently solved, not to mention that is is 2 year old.

Also, the initializations usually take place inside the Constructor or during declaration:

class Main { 
    
    String s = "aaa";
    
    public Main() {

    }
    
    void displayStuff() {
        System.out.print("The length of '"+s+"' is: ");
        System.out.println(s.length());
    }
}

Or

class Main { 
    
    String s = null;
    
    public Main() {
           s = "aaa";
    }
    
   public Main(String s) {
           this.s = s;
    }

    void displayStuff() {
        System.out.print("The length of '"+s+"' is: ");
        System.out.println(s.length());
    }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After taking a closer look at the code you don't need the casting. Since you read from the file a Music object, it doesn't matter what type of music it is:

while (true) {
     Music music = (Music)inFile.readObject();
     musicArray[count] = music;
     System.out.println(count+": "+musicArray[count]);
     count++;
}

Also I would suggest to put the EOFException inside the while loop.

while (true) {
     try {

     } catch (EOFException eofe) {
         break;
     }
}

Leave the rest of the exceptions outside. With that way you will exit the loop once you are done reading the file and then you can do whatever you want with the array, without having to end the program.
Then after the while loop through the array and print its elements

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Even though from your code you have figured out on your own how to use array of objects here is a small example:

Music [] array = new Music[3]; // array is an array and it is not null

// Its elements are so you need to initalize them
array[0] = new RockSong();
array[1] = new ClassicalPiece();
array[2] = new Musical();
// array[0], array[1], array[2] are Music

for (int i=0;i<array.length;i++) {
   if  (array[i] instanceof RockSong){
        RockSong rs = (RockSong)array[i]; // this is how you cast
  } else ...
}

Now as far as the rest of your code:

This is an endless loop because you don't specify when to stop, nor you know the end of the file or how many Music objects are in the file.

while (true)
{
    Music music = (Music)inFile.readObject();

I don't know what will the method do if there are no more objects. Maybe that is why you are getting a NullPointerException. Try to print what you get as soon you read the file and try it with a small file that has only 2 objects

Second, What is the format of the file. I mean how were the objects serialized?


Also here a suggestion depending on your requirements.
Another way for the file to have more than one Music objects then why don't you serialize a Vector:

Vector<Music> v = new Vector<Music>();

v.add(new RockSong());
v.add(new ClassicalPiece());
v.add(new Musical());

// serialize the Vector in the file.
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

can anyone solve this problem?

Yes we can and so can you; after you've been told how in the previous posts.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all, don't do this:

for (int i = 0; i < 20; i++)
...
for(int i=0; i <12; i++)

Use the length of the array:

for (int i = 0; i < tran.length; i++)
...
for(int i=0; i <inter.length; i++)

How do you know the length of an array that is passed as parameter?

-------

And as for your problem if you had tried a little you could fix it. Instead, when the slightest error occurred you immediately rushed to have someone else find it for you.

Give it a go, look carefully your code and you will find.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Use code tags and post only relevant code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi,
Try this code if you haven't solved the problem yet.
Hope it helps you and others having the same problem.

This is a good example. The only difference is that the OP wants the numbers to be printed descending:
10, 9, 8, 7, 6

But you don't have to give him the entire solution. By using your example and my suggestions he should be able to figure this out on his own.


We give them enough information to correct their mistakes and reach to the solution on their own.

There is nothing more we can say to this one. If he can't solve the problem with all that help, we will not hand him the ready solution.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Use the String.charAt() method to loop and get each character.
Then have a HashMap.
Whenever you get a character check the map. If it is in there then take the value stored, increase it by one and then put it in the map to replace the old value.
If it is not in the map, just put it with initial value 1.

Check the API for the HashMap class.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't believe that getClickCount does what you think it does. Nor if you get the Point, you will be able to find which button was clicked.

If all you want is to disable the button then:

buttons[i].addActionListener(new java.awt.event.ActionListener() {
                                     public void actionPerformed(ActionEvent e) {
      JRadioButton source = (JRadioButton)e.getSource();
      source.setEnabled(false);
                                     }
                                     });

The e.getSource() returns the same instance, so it will disable the button clicked.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you want to use a .txt file, and you find databases difficult find examples on how to read files in this forum using the Scanner class or the BufferedReader class.
After you read the file into a Vector or ArrayList check the username and password entered to see if they exist in the data read from the file.

For databases and how to login, check the jsp forum. There is an example on top called MVC. You can read and take the database and validation part.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
for (int i = 0; i < itemCount; i++)
	    contents += cart[i].toString() + "\n[B]"[/B]

	contents += "\nTotal Price: " + fmt.format(totalPrice);

First of all, I think you missed a " after the \n inside the loop.
Secondly, cart is an int. Where did you see written that ints have methods?
The cart doesn't have a method toString because it is an int. You can't make up from your mind methods and call them and then wonder why the code doesn't run.

This is going to work:

for (int i = 0; i < itemCount; i++)
	    contents += cart[i] + "\n";
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The problem I am having is getting the out of bounds exception to work without calling either of the other two catches.

I don't really get the above, but I have a few corrections to add.

First, don't use the toString method of the exception. Use the getMessage to print the error.

String output2 = "Incorrect datatype entered for textfield 2\n" +
"Occured after pressing enter in the 1st textfield\n" +
"Enter appropriate datatype\n" + ex2.getMessage();

And secondly whenever you catch an exception, you print the error and then you continue with the execution of the program. If an exception occurred (user entered non numeric) you shouldn't continue with the rest of the program. So I would suggest to put a return statement at the end of each catch:

catch (Exception ob) {
                    String output2 = "Index is out of bounds\n" +
                            "Exception occured after pressing enter in the first textfield\n" +
                            "Re-enter a selection in the range of " + MIN_INDEX + " - " + MAX_INDEX;
                    ob.toString();
                    JOptionPane.showMessageDialog(null, output2);

[B]return;[/B]
                }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That is why:

while () {
  
  [B]int product[/B] = ...
}

while () {
  
  [B]int product2[/B] = ...
}
if ([B]product[/B]==[B]product2[/B]) {
..
}

You declare the variables inside the while loops and then you try to use them outside. You cannot use a variable outside from the block it was declared.
Declare them outside and give them value inside the loop.

And when you posted your code, you didn't explain anything about your problem. Posting your code doesn't mean anything. Shouldn't you mention the "little" detail that the code doesn't compile?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The split returns an array. And you try to cast it to ArrayList.
From the String get the String [] array using the split method.
Then loop through the array and add its elements to an ArrayList