Solved

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

Posted on 2003-11-19
4
234 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 45
How to convert String matching to regex in java 4 48
Bot application - advice 3 36
Need Help! Getting a syntax error and don't understand why 3 31
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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

766 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