Solved

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

Posted on 2003-11-19
4
219 Views
Last Modified: 2010-03-31
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
Comment
Question by:MarkThompson417
  • 3
4 Comments
 
LVL 15

Expert Comment

by:jimmack
ID: 9780998
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
 
LVL 15

Accepted Solution

by:
jimmack earned 20 total points
ID: 9781013
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9781037
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
 
LVL 35

Expert Comment

by:TimYates
ID: 9781115
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

910 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

24 Experts available now in Live!

Get 1:1 Help Now