473,472 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

String Array

63 New Member
Expand|Select|Wrap|Line Numbers
  1. public String[] gen,temp,backup;
  2.  
Now I need to declare them as array of unknown size. I tried

Expand|Select|Wrap|Line Numbers
  1. // Try 1
  2. this.gen    = new String[];
  3. // Try 2
  4. this.gen    = new String[' '];
  5.  
  6.  
Nothing seems to work can anyone help me with this please.
Jan 26 '08 #1
6 2164
r035198x
13,262 MVP
Expand|Select|Wrap|Line Numbers
  1. public String[] gen,temp,backup;
  2.  
Now I need to declare them as array of unknown size. I tried

Expand|Select|Wrap|Line Numbers
  1. // Try 1
  2. this.gen    = new String[];
  3. // Try 2
  4. this.gen    = new String[' '];
  5.  
  6.  
Nothing seems to work can anyone help me with this please.

Why not throw everything away and use ArrayLists instead?
Jan 26 '08 #2
hsn
237 New Member
the last poster is correct.
if you want to create an array without a size you cant do that with a normal array you have to use ArrayList or Vectors.
with them you don't need to declare any size. you just add the element to the vector or to the arraylist.
good luck
Jan 26 '08 #3
bchaib
20 New Member
Expand|Select|Wrap|Line Numbers
  1. public String[] gen,temp,backup;
  2.  
Now I need to declare them as array of unknown size. I tried

Expand|Select|Wrap|Line Numbers
  1. // Try 1
  2. this.gen    = new String[];
  3. // Try 2
  4. this.gen    = new String[' '];
  5.  
  6.  
Nothing seems to work can anyone help me with this please.
If you don't know how many strings you are going to use don't use arrays but arraylists or other classes from collections ..
When you make this:
this.gen = new String[];
you have to tell the memory how many adresses it has to allocate for you array
for example

this.gen = new String[453234];
String[] gen; // declares an array of strings (strings = array of charachters)
gen= new String[196868]; // allocates memory for 196868 strings

gen[0] = new char{'a','b','c','d'}; // initialize first element

...
Jan 27 '08 #4
JosAH
11,448 Recognized Expert MVP
gen[0] = new char{'a','b','c','d'}; // initialize first element
...
That of course doesn't even compile ...

kind regards,

Jos
Jan 27 '08 #5
bchaib
20 New Member
That of course doesn't even compile ...

kind regards,

Jos
That is absolutly not a Java implementation, but that's how it works ..

Implementation you should give a string
strVar[100] = some string

thanks
have a nice day
Jan 27 '08 #6
amolbehl
63 New Member
Wow thanx a lot arrrayList thing worked great for me thanx a lot everyone.
Jan 27 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
4
by: songkv | last post by:
Hi, I am trying to reassign an array of char to a string literal by calling a function. In the function I use pointer-to-pointer since I want to reassign the "string array pointer" to the string...
22
by: spike | last post by:
How do i reset a string? I just want to empty it som that it does not contain any characters Say it contains "hello world" at the time... I want it to contain "". Nothing that is.. Thanx
4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
14
by: Bob | last post by:
I have a function that takes in a list of IDs (hundreds) as input parameter and needs to pass the data to another step as a comma delimited string. The source can easily create this list of IDs in...
8
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of...
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
11
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
14
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.