Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How can I store a string in an array?

  Date: Nov 24    Category: Java    Views: 750
  

I 'm a beginner in Java Programming,I have 2
problems:
1)How can I store a string in an array?
"for example I want to store a string of 30 letters in an array "A"
of 100 spaces.the string stores from the block A[99] to A[66] ; and
after that I will store "-1" in blocks A[0] to A[65];"

2)I use JBuilder7 ( Borland) to run my programs for applications,but
sofar I couldn't run any program becouse it gives too many errors!!
I don't know what should I do?!and for running the applets ,which
applet viewre I should use?!(Or can I download any software from
internet to solve my problems??!)

Share: 

 

1 Answer Found

 
Answer #1    Answered On: Nov 24    

1. If you want to make an array of strings, simply declare it like
this:
String A[] = new String[n];
The 'n' is the number of strings you want in the array. On a side
note, a string is made up of characters, and "-1" is 2 characters,
a '-' and a '1'. It would be helpful to know why you are trying to
do this in the first place... The most I can deduce is that you
might have come from programming in C++ and are thinking of storing
an array of characters, and are wanting to set the max value of
characters to be stored in the string to 99. If this is the case,
you do not need to do his. The String class does this for you, and
is not limited by the number of characters (I'm not sure, maybe if
you tried to store an extreemly large string, it might give you an
error). At any rate, just declare it the way shown above, and you
should do fine.

2. I personally have not used Borland JBuilder. I use JCreator
from www.jcreator.com . If you go and download that, it will run
the application/applet automatically; all you have to do is press
one button to compile and another to run (refer to the manual).
This program is free, but there is a ($65) pro version for it with
some extra features which are nice, but more than everything you
need is in the freeware version.

 
Didn't find what you were looking for? Find more on How can I store a string in an array? Or get search suggestion and latest updates.




Tagged: