Solved

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

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
firstChar challenge 13 84
create a gui in perl 3 45
JAVA part two 5 41
github account with ecipse 1 17
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

706 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

17 Experts available now in Live!

Get 1:1 Help Now