TeamJava Forum

[ Read Responses | Post a New Response | Return to the Index ]
[ Previous | Previous in Thread | Next ]


Hi Rob, try this, does it help?

Posted by igor on Thursday, 7 August 2003, at 5:11 p.m., in response to Create storage for the list of phrases - arrays HELP?!, posted by Rob on Saturday, 26 July 2003, at 4:46 p.m.

package ...;

public class MyTest
{
public static void main(String[] args) {

ListOfStrings los = new ListOfStrings();

System.out.println("Count:" + los.getCount());

los.addString("First string");

System.out.println("Count:" + los.getCount());

for (int i = 0 ; i System.out.println("String[" + i + "] : "+ los.getString(i));

los.addString("Second string");

los.addString("One more string");

System.out.println("Count:" + los.getCount());

for (int i = 0 ; i System.out.println("String[" + i + "] : "+ los.getString(i));

}

};

class ListOfStrings
{

private String[] storage;
private int count;

public ListOfStrings()
{

storage = new String[10];

count = 0;
}

public void addString(String str)
{

if ( count > 9 )

throw new RuntimeException("The storage is full!");

storage[count] = str;

count++;
}

public int getCount()
{

return count;
}

public String getString(int index)
{

if ( index > 9 || index throw new java.lang.IndexOutOfBoundsException();

if ( index return storage[index];

else return "";
}

}


Responses


Post a New Response

Please select: Discussion Question Answer
Pulse Check - enter num: 1068139330

Your Name:

E-Mail Address:

Subject:

Message:


If you'd like to include a link to another page with your message,
please provide both the URL address and the title of the page:

Optional Link URL:

Optional Link Title:


If you'd like to have the option of deleting your post later,
please provide a password (CASE SENSITIVE!):

Password:



Password:

The TeamJava Forum is maintained with WebBBS 2.24.


TeamJavaHome | Ind. Registry | Co. Registry | Java Links
Jobs Listings Forum | TeamJava Books | Java FAQ Archives

AWN

Copyright © 1995-2003 Active Web Networks, all rights reserved.
(Note: We share no direct association with Sun Microsystems, Inc.)