[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2003-11-19
4
Medium Priority
?
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 80 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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

656 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