473,226 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

unknown -size initialization of an array

13
hello,

may I know the method to create an array with unknown size?
in C , one can go for malloc.
what is the method in java?

regards,
bela
Sep 20 '07 #1
9 24352
Nepomuk
3,112 Expert 2GB
hello,

may I know the method to create an array with default size?
size is unknown to me initially.

regards,
bela
I don't think, there is a default size for arrays in Java initially, but you can always do something like this:
Expand|Select|Wrap|Line Numbers
  1. int defaultSize = 10;
  2. int size;
  3. // try to get the size from somewhere, if no size is given, set size = defaultSize
  4. int[] array = new int[size];
  5.  
Greetings,
Nepomuk
Sep 20 '07 #2
bela
13
I don't think, there is a default size for arrays in Java initially, but you can always do something like this:
Expand|Select|Wrap|Line Numbers
  1. int defaultSize = 10;
  2. int size;
  3. // try to get the size from somewhere, if no size is given, set size = defaultSize
  4. int[] array = new int[size];
  5.  
Greetings,
Nepomuk
thank you.
I'm sorry, I want to say array of unknown size.
in C, using malloc, we can assign memoey,
how can we do this in java?
regards
Sep 20 '07 #3
Nepomuk
3,112 Expert 2GB
thank you.
I'm sorry, I want to say array of unknown size.
in C, using malloc, we can assign memoey,
how can we do this in java?
regards
I'm not familiar with C, but as far as I know, C (and C++) are much less strict when it comes to arrays than Java. If you want a Collection, which you can change the size of, use a Vector. It will automatically adjust it's size to what you enter into it. Otherwise, it's not much different to an array.

Greetings,
Nepomuk
Sep 20 '07 #4
r035198x
13,262 8TB
thank you.
I'm sorry, I want to say array of unknown size.
in C, using malloc, we can assign memoey,
how can we do this in java?
regards
Use arraylist instead. Array length is fixed in java and should be specified when the array is initialized.
Sep 20 '07 #5
bela
13
I'm not familiar with C, but as far as I know, C (and C++) are much less strict when it comes to arrays than Java. If you want a Collection, which you can change the size of, use a Vector. It will automatically adjust it's size to what you enter into it. Otherwise, it's not much different to an array.

Greetings,
Nepomuk

Thank you.
Its working.

regards,
bela
Sep 20 '07 #6
bela
13
Use arraylist instead. Array length is fixed in java and should be specified when the array is initialized.

yes, it also working.
thank you.
regards,
bela
Sep 20 '07 #7
r035198x
13,262 8TB
I hope you googled for ArrayList vs Vector.
Sep 20 '07 #8
Nepomuk
3,112 Expert 2GB
I hope you googled for ArrayList vs Vector.
I have now... learned something again! :-)

Greetings,
Nepomuk
Sep 20 '07 #9
bela
13
I hope you googled for ArrayList vs Vector.

Yes, me too.

regards,
bela
Sep 21 '07 #10

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

Similar topics

4
by: Jason Heyes | last post by:
Why does Foo.h need to be included in Bar.cpp for this program to compile properly? I define the FooList destructor in a separate module so that a forward declaration to Foo can be used. //...
2
by: cjl | last post by:
Hey all: I have a div of a known size, 672px X 672px. In it I will display images that are of unknown size. I have two simple functions that shrink and center the image: function shrink() {...
12
by: manochavishal | last post by:
Hi, I have a question. How can i know the size of array when it is passed to a function. For Example i have this code: #include <stdio.h> #include <stdlib.h>
1
by: Betsy | last post by:
I'm trying to do some pointer manipulation and can not avoid using void * as the type declaration. I get this error message : error C2036 : 'void *' : unknown size though. Is there a compiler...
3
by: manoj.pattanaik | last post by:
Hi, I am trying to compile following piece of code (bb.cpp) using aCC (HP ANSI C++ B3910B A.03.37) compiler on HP-UX 11.23. It gives error:485 //bb.cpp -- Starts #include <iostream> using...
5
by: desktop | last post by:
I have a function that takes two pointers to an array. The first point to the first element while the other points to the last element. int nums = { 1, 2, 3, 4, 5, 7, 8, 9}; int* result; int...
3
by: cppman | last post by:
Hello, I am very new to C++ programming. I am trying to read a file with very large strings back to back, no commas or any other seperations between characters in a string and the size of the...
4
by: shapper | last post by:
Hello, I have been reading a few articles about font sizing and I get various versions. All them say to use em ... ok that is what I use. But then they differ on the text size "initialization"....
7
crystal2005
by: crystal2005 | last post by:
Hi everyone, I gonna ask how to set unlimited size of array of characters. According to the tutorial that i have found after amount of time of googling, array size should be defined when we...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.