Avatar of Ashok
AshokFlag for United States of America

asked on 

Convert 3 lines of JavaScript code to Java (Part 2) - For CEHJ

CEHJ,

I want to be able to add a row in one procedure
and
assign value to one column in another procedure
and
assign value to second column in third procedure.

Using the code you gave me earlier.  I am confused.

For example, in JavaScript
arrMem[currArr] = new Array(2); // Adds a row in the array.

arrMem[currArr][0] = lblText;  // How I assign value to one column.

Both lines are in separate procedures.

So my problem is... when I add a row, I do not know values.
Also, I may not know values of both columns at the same time.

Thanks,
Ashok




JavaJavaScript

Avatar of undefined
Last Comment
CEHJ
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

http://download.oracle.com/javase/6/docs/api/java/util/List.html#set(int, E)

is probably what you need. You can't use that if the element doesn't exist though, so if you want to add placeholder to fill later you could do
rowOne.add("");
rowOne.add("");
...
rowOne.set(0, "foo");

Open in new window

Avatar of Ashok
Ashok
Flag of United States of America image

ASKER

I think this will work.

So if I want to set 2nd column's value, I would use

rowOne.set(1, "bar");

Right?

Thanks,
Ashok
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Exactly
Avatar of Ashok
Ashok
Flag of United States of America image

ASKER

  for (var r = 0; r < currArr; r++) {
           for (var c = 0; c < 2; c++) {
              arrMem[r][c] = '';   // confused here
        }
   }

I need help to convert above code....

Thanks,
Ashok
Avatar of Ashok
Ashok
Flag of United States of America image

ASKER

arrMem.set(r).set(c) = "";

Is that correct?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Are we assuming the nested collection is already filled (even to null or empty String)?
Avatar of Ashok
Ashok
Flag of United States of America image

ASKER

already filled = YES

array.get(0).set(0,"Foo");
array.get(0).set(1,"Bar");

Is above code valid?

Thanks,
Ashok
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Ashok
Ashok
Flag of United States of America image

ASKER

I ran above code.

Made following modification to assign all values like.....

      arrMem.get(0).set(0, "Foo");
      arrMem.get(0).set(1, "Bar");
      arrMem.get(1).set(0, "Foo2");
      arrMem.get(1).set(1, "Bar2");

Working as expected.

Thanks,
Ashok
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

:)
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo