• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

2 questions: One on arrays, the other on clearing the screen.

Hi, I have two questions that I need to be answered involving java.
1.  Is it possible to expand an array after it has been initiated?  If so, how?
2.  I need to clear the screen and I'm not too familiar with classes, so I don't know how to incorporate much GUI or graphics.  How can I do this?
0
MarkThompson417
Asked:
MarkThompson417
  • 3
1 Solution
 
jimmackCommented:
1. No.  You would have to create another array of the size you require, then copy the original array contents across.

2. Clear the screen in what way?  If you have a text area or text field, you can usually use a method like setText("") to clear the content.
0
 
jimmackCommented:
If you need an array that is expandable, you should use a java.util.ArrayList.

You can access it's entries using and index (starting at 0) if you want:

ArrayList al = new ArrayList();
al.add("First");
al.add("Second");
al.add("Third");

System.out.println((String)al.get(2));

Or, more usually with ArrayLists, you would "iterate" through it, using:

Iterator it = al.iterator();
while (it.hasNext())
{
    String content = (String)it.next();
}
0
 
jimmackCommented:
There are several alternatives to an ArrayList, including, but not limited to:  Vector, LinkedList, Hashtable...

Each provides different facilities, so you'll need to look at the javadocs to decide what you actually need.  eg. a Vector is the same as an ArrayList, but it is thread safe.  Hashtables store key-value pairs (both Objects), etc.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now