Array of structure
can i declare a structure as in C language, then to use it as an array.....
but this time i want to use java....
how can this be done...
let say my structure have studid and age,
i want my array to be of size 3....
pls help
i mean....
i want to declare a structure with studid and age in
it......
then i want this structure to an array of size 3...can
this be done??
how can this be done??Java has no notion of structures, which is understandable, since Java is an object-oriented programming language, hence there is no need for those. You can, however, use classes as structs. For example:
class MyStructure {
public int age;
public int studid;
}Then you could refer to that as you would refer to a structure (of course you would have to create an instance first).
MyStructure[] struct = new MyStructure[3];
for(int i = 0; i < 3; i++)
struct[i] = new MyStructure();
// Then you can use the structure
struct[0].age = 22;
struct[1].age = 47;
struct[2].age = 33;Tuomas Rinta
Similar Messages
-
Loops in arrays or structures
I was given a project on html reports and
They have advised me to use Loops in arrays or structures
At this point I am a novice at this html reporting system. I
would like to know how I can use loops in arrays or structures.
How is it beneficial are
1. Structures
2. Arrays
3. loops in for both
for my reports.
Countless thanks in advanceStructures are great if you understand them, they are
basically just arrays organized by keywords rather than index
numbers.
Arrays are very nice, as you can just run through loops to
access each element, as they are all indexed by numbers 0-x.
loops are great to navigate through both. All you have to do
is set an loop to run through x amount of iterations of the array
or structure (where x is the length of the array, or number of
elements in the structure). Loops are great due to the small amount
of code they require. -
How to create an array of structure which the structure contain an array(s)
im very new to java, and new here
i searched many websites, but i cant find it
it looks like this,
there is 10 employees, each of them has 0-5 children,
what i want is,
peter alan joseph
|?????????????????|???????|??????????????
| |????????| |??????| | |?????| |
| | andrew | | alvin | | | john | | ...........................
| |________| |______| | |_____| |
| |
what i know is,
import java.util.*;
class main{
public static void main(String[] args){
employee d[] = new employee[10];
d[0]= new employee();
d[0].child = "alvin";
System.out.println(d[0].child);
class employee{
String child;
}but only work for 1 child.. =(
i need an array of structure which the structure itself cantains an array(s)
please help, newbie heresen,
my lecture[r] said no statement in classEither you misundetstood your lecturer [probable]; or your lecturer is full of shit [possible].
is "String[] children = new String[5]" a statement ?Yes, it is.
she said we can only declare like "String[] children;" in classEither you misundetstood your lecturer ...
There's nothing actually wrong withclass Employee{
String[] children = new String[5];
}But it has the inherent limitation that you can't put the fathers name on the 6'th child's birth certificate... because the dumb computer won't let you... Hence it is poor practice.
A better implementation would be:class Employee{
private List<String> children = new ArrayList<String>();
}because it doesn't impose an artificial limit on the number of kids a bloke can have.
keith. -
Is there a way to pass an array or structure for example as parameters, in addition to a query, or multiple queries to the Report Builder in CF8? I believe this was recommended by users to be in CF8.
BrianO,
Although it's been a while, I thought I'd provide the code to do this for you. It works for me in CF8, and probably will in CF7.
Here I create a structure called My, and provide that one parameter to my CFReportParam tag.
<CFSet My = {
Client = "Client Name",
ReportDateFrom = DateFormat(ThisStartDate, DateMask),
ReportDateTo = DateFormat(ThisEndDate, DateMask),
PageHeaderImage = ImagePath & "\Logos\Page_Header.png",
WatermarkImage = ImagePath & "\Logos\Watermark.png",
GetBarSummary = GetBarSummary,
GetPieSummary = GetPieSummary
}>
<CFReport Template="#ReportPath#\SpendSummary.cfr" Format="PDF" Query="GetSummary">
<CFReportParam Name="My" Value="#My#">
</CFReport>
Inside the report itself, reference the given parameter as Param.My.PageHeaderImage for example. It can be referenced that way from any expression inside the report builder. You can even use the queries as the data source for charts (using the Data From a Query -> Query Builder -> Advanced) by entering "Param.My.GetPieSummary" where it says "Variable containing query object".
HTH
Swift -
How to pass a structure/array of structure as input parameter in a webservice
Hi Team,
I am trying to create a webservice in powerbuilder .net( pb 12.5.1) . As this webservice will be used by external world to access some of data on basis of some input paarameter.
So can i use array of structure as input parameter to a webservice ? If no, then how can i pass a result set ( mora then 1 row with more than one column)
as an argument to the webservice.
Regards
SubratI am assuming this is the same for .Net but in Classic you can create NVO's with Instance Variables and then reference them in the NVO that will be used as the parameter for the Public WebService.
WS NVO's:
Children
String Child[]
Customer
String FirstName
String LastName
String DOB
Children Children
Public Interface uses Customer
Calling Code Example:
integer rc, liNdx
string lsReturn
SoapConnection lSoapConnect
proxy_testing px_Testing
lSoapConnect = CREATE SoapConnection
if IsValid(lSoapConnect) then
TRY
rc = lSoapConnect.CreateInstance(px_Testing, 'proxy_testing')
CHOOSE CASE rc
CASE 100
lsReturn = "Invalid proxy name"
CASE 101
lsReturn = "Failed to create proxy"
CASE 0
Proxy_Customer lNewCustomer
lNewCustomer = CREATE Proxy_Customer
lNewCustomer.FirstName = 'Chris'
lNewCustomer.LastName = 'Craft'
lNewCustomer.DOB = 'Getting Older'
Proxy_Children lChildren
lChildren = CREATE Proxy_Children
lChildren.Child[1] = 'Madeline'
lChildren.Child[2] = 'Hayden'
lNewCustomer.Children = lChildren
lsReturn = px_Testing.NewCustomer(lNewCustomer)
CASE ELSE
lsReturn = "Unknown error (" + String(rc) + ")"
END CHOOSE
if rc <> 0 then MessageBox("Invocation Error", lsReturn, Exclamation!)
CATCH (RuntimeError rte)
rc = -1
MessageBox("Runtime Error", rte.text, Exclamation!)
END TRY
end if
Chris Craft -
The suitable LabVIEW data type correspinding to the array of structure in Visual Basic ActiveX DLL
Hi!
I need to call a VB ActiveX DLL from LabVIEW. When I run my LabVIEW code, I always meet an error as:
Error 1 occurred at Incorrect Function in T06.vi
Possible reasons:
LabVIEW: An input parameter is invalid.
I have read the VB DLL code that defines the data type. It fills data to a structure, then puts this structure to the array, and sends the array of structures to the method.
VB Code:
For I = 1 To 31
Set MyInputData(I) = New EM_nkd_DataPoint
Next I
With MyInputData(1)
.Amplitude = 8.44
.DataPointType = R_HW
.DataSource = MEASURED
.Wav
elength = 409.56
End With
With MyInputData(2)
.Amplitude = 91.60113
.DataPointType = T_SUB
.DataSource = MEASURED
.Wavelength = 409.56
End With
~~~
With MyInputData(31)
.Amplitude = 91.96825
.DataPointType = T_SUB
.DataSource = MEASURED
.Wavelength = 657.43
End With
My problem is that I can’t find a suitable kind of data type in LabVIEW which is corresponding to this case
Attached my LabVIEW code for reference.
Many thsnks.
TX
Attachments:
T07.vi 166 KBHi,
if you have a complete source code including EM_nkd_DataPoint class module, take a look inside in order to see data types for Amplitude, DataPointType, DataSource and Wavelength (probably for Amplitude and Wavelength is SINGLE). If this code is not available, maybe the author mentioned a type for T_SUB and MEASURED even if they are constants. -
Accessing Array of Structures from Coldfusion
I am having a problem accessing an array of structures from
Coldfusion within my flex application. Here is how I make my Array:
(GetRegions is a type Query and Type is a string variable)
<cfset ReturnArray = ArrayNew(1)>
<cfset ReturnArray[1] = StructNew()>
<cfset ReturnArray[1].Query = GetRegions>
<cfset ReturnArray[2] = Type>
Within flex I am trying to access the results in the
following way:
private function dataHandler(event:ResultEvent):void{
Query_Filter = new ArrayCollection(event.result[0].QUERY as
Array);
myString = event.result[1] as String;
Can anybody help me with this. I want a way to return a query
and a string back from coldfusion.
Thanks for the help,
JeffSo now I changed my code to the following in CF:
<cfset Type = "MyString">
<cfset ReturnArray = ArrayNew(1)>
<cfset ReturnArray[1] = StructNew()>
<!--- set up query GetRegions --->
<cfset ReturnArray[1] = GetRegions>
<cfset ReturnArray[2] = Type>
<!--- Return Array --->
<cfreturn ReturnArray>
Now in flex I have the following dataHandler Function:
Alert.show("hello: "+ObjectUtil.toString(event.result[0]));
Query_Filter = new ArrayCollection(event.result as Array);
Now I set up a List box with Query_Filter as the dataprovider
but the results aren't showing correctly. The first item in the
list box is displayed as [object, Object], [object, Object] and the
second item is my String.
Does anybody know how to break up the query to a variable and
the string to its own variable in the dataHandler function.
Thanks for any and all help -
Passing an array of structures to an Oracle stored procedure (CFMX)
I'm looking to write a Oracle stored procedure where I would pass in an array of structures and loop over each iteration to insert the bits and pieces within the structures to the DB.,
I haven't written this type of procedure / package before. I am planning to do an sp / package similar to what is sketched out in the second reply to this thread: http://forums.oracle.com/forums/thread.jspa?threadID=1078772
Assuming I do, how can I call the procedure from ColdFusion (I'm using MX) and pass in my array? As far as I can see, none of the CF_SQL_Types make sense.Let me know if you make any progress. I'm fighting the same battle. What I've done so far is to convert my array of struct into a delimited CLOB that looks like this:
prop1;prop2;prop3|prop1;prop2;prop3|prop1;prop2;prop3|prop1;prop2;prop3|
Then I wrote a stored proc to suck it up using a pipelined function. It's not to bad but parsing the CLOB on the ORACLE side is somewhat time consuming.
I've also converted the array to XML and used dbms_xmlstore to convert but, on large arrays, it is very slow and the CLOB gets huge fast.
I was hoping to use the cf_sql_refcursor but I can't figure out how.
Warren -
Array of structures - two ways to approach - which is better?
Folks - I've been trying to create an array of structures,
but I bumped into problem that lead me to an example that is
completely different. I'm trying to figure out which is valid. In
general, it comes down to this:
(1) myStructure
.firstName
vs
(2) myStructure.firstName
The problem with the first is that I can't find a way to
discover the size of the array, which leads me to suspect this is
not a valid method. The problem with the second is that you must
redefine the structure for EACH array element, which seems like it
would add a lot of overhead.
Any advice? Sample code attached.
Thanks!
************* Sample (1) **************
<CFSET sCust=StructNew()>
<CFSET vCustCount = #rsMailAuth.recordcount#>
<CFSET i = 0>
<CFOUTPUT QUERY="rsMailAuth">
<CFSET i = i+1>
<CFSET sCust.userId
= #rsMailAuth.userId#>
<CFSET sCust.validEmailSource =
#rsMailAuth.validTcEmails#>
<CFSET sCust.authKeyword
= #rsMailAuth.tcEmailKeyword#>
<CFSET sCust.authKeywordLoc =
#rsMailAuth.tcEmailKeywordLoc#>
</CFOUTPUT>
************* Sample (2) **************
<cfset strTest = arrayNew(1) >
<cfset strTest[1] = structNew() >
<CFLOOP INDEX = "i" FROM="1" TO="5" >
<cfset strTest
= structNew() >
<cfset strTest.id = i>
<cfset strTest
.name = "[email protected]">
</CFLOOP>
<cfoutput>#arrayLen(strTest)#</cfoutput>Sorry - simple english...
I am collecting a series of emails from a pop email server.
As I parse these into the individual parts (subject, body, from,
etc) I want to stuff them into a structure. each email would be a
new index. so, the 2nd email 'from' info would go into
myStructure.from[2] or myStructure[2].from.
I know there are lots of ways around this, I just have a
natural predisposition to use structures when possible as it makes
it easier for me to keep track of things and makes it easier to
follow the code.
I can make either of these work, I'm just not sure if they
are valid in the world of coldfusion8. -
Passing array of structures back to java from c
I have a DLL in C that I'm calling from a Java servlet. The C DLL creates a bunch of arrays of structures that I would like to be able to bring back to the Java servlet and process further. How difficult is this and does anyone have anywhere to point me that shows how it can be done?
1. In general, java knows nothing about structures. So you have to define eqquivalent java classes, and write code to move the data from C structs into the classes.
2. JNI supports definition of arrays of objects, which can be passed back from the dll.
You may find some code generators that will help you with the
CStruct->JavaObject definition. This may be a blind alley, but check out JACE. -
Assign global array of structures of structures of std strings in a dll
I have a dll which consists of three c files. Find bellow the c file of the loader and the three files of the dll. In dll, file 1 and file 2 are almost identical, static arrays names and sizes, structure names, Prepare_1() and Prepare_2() functions. There
is a small difference in the function Prepare_1 in the way MuxStatusSupl[ u32Idx ].FileInfo.Name is assigned and there I get an exception. Another difference is that the structure StructStatus in file 2 has an extra member compare to file 1. From this point
I couldn't strip down even more the sample code because small changes make the problem disappear without, I'm afraid, really solving the problem. That's why I have put so much code here, I'm not even sure what is relevant and what not. For example, if I add
in file 1 in the StructStatus the extra member u32ExitPoint (and, of course, I modify Status_Init accordingly), I don't see the problem anymore.
///////////////////////////////////////////////////// loader file begin ////
#include "stdafx.h"
int main(int argc, char* argv[])
{ HINSTANCE hDLL = LoadLibrary( DLL_FQN_FILE_NAME );
if( void ( * pCreateDllInterface )( void ) =
(void(*)())GetProcAddress( hDLL, "CreateDllInterface" ) )
pCreateDllInterface();
FreeLibrary( hDLL );
///////////////////////////////////////////////////// loader file end //////
///////////////////////////////////////////////////// dll main file begin //
extern void Prepare_1( void );
extern void Prepare_2( void );
extern "C" _declspec(dllexport) void CreateDllInterface( ) { Prepare_1(); }
///////////////////////////////////////////////////// dll main file end ////
///////////////////////////////////////////////////// dll file 1 begin /////
#include <string>
#include <sys/stat.h>
#define STORAGE_SIZE 254
typedef unsigned long int uint32;
struct StructFileInfo
{ std::string Name;
struct stat FileStatus;
static struct StructStatus
{ bool bDownloaded; bool bDownloadedLast;
bool bCalled; bool bCalledLast;
uint32 u32EntryPoint;
StructFileInfo FileInfo;
} MuxStatusMain[ STORAGE_SIZE ], MuxStatusSupl[ STORAGE_SIZE ];
void Prepare_1()
{ struct stat Stat_Init;
memset( &Stat_Init, 0, sizeof(struct stat) );
StructStatus Status_Init =
{ false, false, false, false, 0, { "", Stat_Init } };
std::fill_n( MuxStatusMain, STORAGE_SIZE, Status_Init ); // this seems
// to overwrite MuxStatusSupl[ 3 ].FileInfo.Name
for( uint32 u32Idx = 0; u32Idx < STORAGE_SIZE; u32Idx++ )
MuxStatusSupl[ u32Idx ].FileInfo.Name = ""; // crash when u32Idx==3
///////////////////////////////////////////////////// dll file 1 end ///////
///////////////////////////////////////////////////// dll file 2 begin /////
#include <string>
#include <sys/stat.h>
#define STORAGE_SIZE 254
typedef unsigned long int uint32;
struct StructFileInfo
{ std::string Name;
struct stat FileStatus;
static struct StructStatus
{ bool bDownloaded; bool bDownloadedLast;
bool bCalled; bool bCalledLast;
uint32 u32EntryPoint; uint32 u32ExitPoint;
StructFileInfo FileInfo;
} MuxStatusMain[ STORAGE_SIZE ], MuxStatusSupl[ STORAGE_SIZE ];
void Prepare_2()
{ struct stat Stat_Init;
memset( &Stat_Init, 0, sizeof(struct stat) );
StructStatus Status_Init =
{ false, false, false, false, 0, 0xFFFFFFFF, { "", Stat_Init } };
std::fill_n( MuxStatusMain, STORAGE_SIZE, Status_Init );
std::fill_n( MuxStatusSupl, STORAGE_SIZE, Status_Init );
///////////////////////////////////////////////////// dll file 2 end ///////
I get the crash with the message: Unhalted exception at 0x10001f90 in Test.exe: 0xC0000005: Access violation writing location 0x1006d320
Another strange phenomena is that in watch window, expressions
sizeof(MuxStatusMain)/sizof(MuxStatusMain[0])
sizeof(MuxStatusMain)/sizof(MuxStatusMain[0])
show both a value of 232 instead of 254 (but if I add in file 1 in the struct the missing member they show the correct values). On the other hand, if I printf those values, they are correct, 254."Another difference is that the structure StructStatus in file 2 has an extra member compare to file 1."
That's not going to work. It is possible to define the same struct in different translation units but the definitions need to be identical. Use different names for StructFileInfo and StructStatus. -
Array of (structure) as a parameter in CORBA and JAVA
Hii
i have created a structure in the (interface )IDL file in CORBA program,
then I used an array of this structure.
I used the data type in the server application, i decalared a variable of the same type of the structure and i send it to the client as a single variable, it was working with out problems.
the problem is :
i wanted to send an array of this object (structure) to the client but i couldn't i tried many ways but i couldn't,
I wrote the program (both server and client) in Java, but since i am not java profissional I think there is a certain way to send this array as a parameter from the server to the client or the opposit.
so , Can you please help meIn your idl file you need to define a sequence of your structure
typedef sequence<strucrure name> stucts;
this is mapped to an aarray of your struct in java -
SUPStorage api in SUP 2.1 to store array or structure
Hi,
I am using below code to store key value pair using SUP api for offline storage in workflow apps:
SUPStorage.prototype.setItem(j, airlineId);
Example: var j = 1;
var airlineid = "lufthansa";
This works fine, but I want to store an array or at least a structure (single row) which has multiple items. How can we do that?
I tried passing MBO value data directly, but it gives exception while I try to read:
var mvc = getCurrentMessageValueCollection();
var fData = mvc.getData("flightmbo");
var values = fData.getValue();
var i = 1;
SUPStorage.prototype.setItem(i, values);
This does not give any exception, but when I try to read by using code:
var i = 1;
airlineKey = SUPStorage.prototype.key(i);
values = SUPStorage.prototype.getItem(airlineKey);
var j = 0;
var theItems = values[j];
This gives exception saying "Type Error: Result of expression 'values' [null] is not an object".
Any workarounds to store a structure/array with the same key (such as airline id, text, time, availability).
Thanks,
RohitHave you tried converting the array/structure to a string using JSON (or some similar technique) and storing it that way?
-
Make unique array of structure
Hi all.
How can make array of unique elements ?
Heed to get from array -> array1
<cfset array = arrayNew(1) />
<cfset array1 = arrayNew(1) />
<cfset array[ 1 ] = { id = '1' } />
<cfset array[ 2 ] = { id = '1' } />
<cfset array[ 3 ] = { id = '1' } />
<cfset array[ 4 ] = { id = '2' } />
<cfset array[ 5 ] = { id = '3' } />
<cfset array[ 6 ] = { id = '4' } />
<cfset array[ 7 ] = { id = '4' } />
<cfset array[ 8 ] = { id = '5' } />
<cfdump var="#array#" label="Current" />
<cfset array1[ 1 ] = { id = '1' } />
<cfset array1[ 2 ] = { id = '2' } />
<cfset array1[ 3 ] = { id = '3' } />
<cfset array1[ 4 ] = { id = '4' } />
<cfset array1[ 5 ] = { id = '5' } />
<br /><br />
<cfdump var="#array1#" label="Needfull" />There are a few 'tricks' that you can use here ...
A "struct" is fundamentally an associative-array structure. So, if you've got an "id" field of any sort, a struct can locate any "id" almost instantly. This is much faster than searching an array (which has a hidden cost created by virtual-memory paging over a large "footprint").
When you add a struct to another struct or to an array, you are actually moving a reference to the structure. You should find that (afaik!), if the struct is present both in an array and in a struct, both of these are references to one-and-the-same memory block.
Use the most-convenient data structure when building the original set of records. This is probably going to be a "struct." If you then need to have an array of elements sorted in a particular way, build that array last, by using a "sort" operation to arrange the records in whatever order you want. Since you'are actually (afaik...) moving references, you're not stomping on too much RAM.
"Sorting" is what I call an "unexpectedly fast and efficient" operation, because it's one of the most heavily-studied operations in all of data processing ... and has been since the days of Herman Hollerith. -
Hello All,
I defined a view in my application. This view comprises of a structure
containing an integer and char[].
I my application, I created an array of this structure and populated it.
I return the pointer to the array of the structure in the tpreturn call.
on the client side, I can see that only the first element of the array
is retrievable. The rest is junk data.
Why did the other elements did not come?
when populating the data in the array I do a userlog in the loop and I
can see that each element of the array was populated.
Why am I not able to send the entire array to the client side?
thanks for your help.
regards,
Abhishek.Abhishek,
Make sure that you are using the exact C structure that was produced by the View
compiler from your View description.
Can you post your .v file, and the .h it generated?
If you need to transmit an array of the entire structure, you can use embedded
FML32 to pack many View structures into an FML32 buffer.
If you are always sending between the same machine types and data representations,
and you don't need Routing, then you can stuff your C structure into a CARRAY
and send it that way. On the other side, you'll have to copy it out into a
properly aligned structure.
Scott Orshan
Abhishek Srivastava wrote:
Hello All,
I defined a view in my application. This view comprises of a structure
containing an integer and char[].
I my application, I created an array of this structure and populated it.
I return the pointer to the array of the structure in the tpreturn call.
on the client side, I can see that only the first element of the array
is retrievable. The rest is junk data.
Why did the other elements did not come?
when populating the data in the array I do a userlog in the loop and I
can see that each element of the array was populated.
Why am I not able to send the entire array to the client side?
thanks for your help.
regards,
Abhishek.
Maybe you are looking for
-
Credit Limit Check - Exclude Specific Documents / Credits from Exposure
Hi, I would like to know if it's possible to exclude specific document types (credits) from the credit exposure calculation used during credit limit checks. The ideia is to exclude "DG" credits in customer GL that are related to Trade Deal/Agreements
-
Unable to keep my external hard drive connected to my computer for backup with Time Machine.
I am using an external LaCie hard drive to backup my computer. In the last month or so I have noticed that when my computer is in the sleep mode for sometime the hard drive disconnects from my computer. I than get an error message that tells me tha
-
Problems with servlets.
hi all. i've installed the tomcat 5.5.15 on a windows xp. the servlet examples provided with the tomcat works great but when i try to add a servlet of my own it won't run it.. here's what i get: HTTP Status 404 - /test/ type Status report message /te
-
Big Problem! - Veriation of RSS Problem??
Ok, so as you can see I have the first version of the 2 GHZ Macbook, and I have a HUGE problem! Most of my applications, mainly safari, itunes, iphoto, textedit, pages & ichat shut down on thier own over and over again, a box pops up asking if i want
-
Differnce between MMPV and OB52
Wat is the differnce between OB52 and MMPV, Thanks Ramki