Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How can I store a string in an array?

  Asked By: Jesse    Date: Jul 13    Category: Java    Views: 25184
  

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: 

 

5 Answers Found

 
Answer #1    Answered By: Neil Turner     Answered On: Jul 13

To store  anything in a array  you first need to create the right kind of
array.

Anything[] blah = new Anything[5];

That just made a new Array which can hold 5 Anything objects (Anything
objects is just something I made up, don't expect Anything to realy mean
anything)

To add something into a array you simply

blah[0] = SomeThing;

This just added SomeThing to the array.

That probably isn't as totaly usefull as it seems, infact you probably
need to know how to put many strings into a array. I won't show you the
answer to that but I will lead you to using a for loop to step though
the array.

 
Answer #2    Answered By: Katrina Edwards     Answered On: Jul 13

in project setting add all required libs --jars files
or give the correct project tree structure
src-com-proj,...
set the root as src

 
Answer #3    Answered By: Eddie Austin     Answered On: Jul 13

Since u are a beginner  u can read this for more information



developer.java.sun.com/.../



And u can also download jdk from these links to run your programs

 
Answer #4    Answered By: Antonio Dunn     Answered On: Jul 13

Oh yeah I forgot to post this before.

I wouldn't use any complext IDE untill you start understanding the basic
levels of Java. My recomendation is to use a simple java  editor (like
JEdit) and go with that.

I have seen to many young coders not know the simple stuff (like
classpaths), not to mention that IDEs can overwhelm you with stuff.

What kind of errors do you get in your program that you are running by
the way?

 
Answer #5    Answered By: Holly Brown     Answered On: Jul 13

Question #1: If you really need to store  the string
"-1" in the array  you will have to create an array of
Strings. Then add the string  "-1" to elements 0-65
then add the letters  (actually one character strings)
to elements 66-99.
Ex.

int negOneLimit = 65;
String[] A = new String[100];
String negOne = "-1";
String someRandomChar = "X";
for(int i = 0; i < A.length; i++){
if(i <= negOneLimit)
A[i] = negOne;
else
A[i] = someRandomChar;
}

Note that there is not character representation for
"-1" so I had to use an array of strings. If you can
substitute "-1" for a single character then you would
use an array of char instead.

Question #2: You will have to post the error messages
that you get here if you want someone to help you.

 
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: