arraylist of characters 1

arraylist of characters

  import java.util.ArrayList;

  public class Test{

       String words = new String("HELLO GOODBYE!");
       ArrayList sample = new ArrayList();

       for(int i = 0; i

Here is what the above code is Doing:
1. We create a String object called words and assign it the value "HELLO GOODBYE!"
2. We create an ArrayList object called sample and assign it an empty ArrayList
3. We create a for loop that iterates through the length of the words String
4. We add each character of the words String to the sample ArrayList

The above code is a bit more complicated than what we've seen before, but it's not too bad.

Let's break it down:

1. We create a String object called words and assign it the value "HELLO GOODBYE!"

This is pretty straightforward. We create a String object called words and assign it the value "HELLO GOODBYE!"

2. We create an ArrayList object called sample and assign it an empty ArrayList

This is also pretty straightforward. We create an ArrayList object called sample and assign it an empty ArrayList.

3. We create a for loop that iterates through the length of the words String

This is a bit more complicated. We create a for loop that iterates through the length of the words String.

4. We add each character of the words String to the sample ArrayList

This is also a bit more complicated. We add each character of the words String to the sample ArrayList.

Let's look at the for loop in more detail:

for(int i = 0; i

Similar Posts