Results 1 to 7 of 7
Thread: make elements
- 05-18-2016, 03:41 PM #1
Member
- Join Date
- Apr 2016
- Posts
- 27
- Rep Power
- 0
make elements
Hope you can help me. In previous online exercises, I was able to make elements of an object by hand:
Java Code:A A1 = new A(); A A2 = new A(); B B1 = new B();
Java Code:public static void makeB(List<A> listOfA) { for (A a : listOfA) { new B(); //HOW?? } }
Last edited by casta; 05-18-2016 at 05:19 PM.
- 05-18-2016, 03:51 PM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: make elements
To do that you only need a count of the elements in the list of A (the elements themselves are not used). So simply use a for loop
with a limit based on listOfA.size() and add the new B elements to a new List implementation.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 05-18-2016, 04:10 PM #3
Re: make elements
Note: The posted code has several syntax errors in it that make the code harder to understand.
A A1 = new A; // missing ()s after A
for (Egg A : listOfA) // If listOfA contains A objects then "Egg A" is wrong. I should be "A egg"
When posting code you should try to post valid code so we can know how good your java knowledge is.Last edited by Norm; 05-18-2016 at 04:17 PM.
If you don't understand my response, don't ignore it, ask a question.
- 05-18-2016, 05:21 PM #4
Member
- Join Date
- Apr 2016
- Posts
- 27
- Rep Power
- 0
- 05-18-2016, 05:27 PM #5
Re: make elements
how could I instantly give each element a reference variable?
A reference to an instance of a class can be saved in a collection like an ArrayList or in an array.If you don't understand my response, don't ignore it, ask a question.
- 05-18-2016, 05:29 PM #6
Member
- Join Date
- Apr 2016
- Posts
- 27
- Rep Power
- 0
- 05-18-2016, 05:29 PM #7
Member
- Join Date
- Apr 2016
- Posts
- 27
- Rep Power
- 0
Similar Threads
-
How to make a make a Console program?
By Snake006 in forum New To JavaReplies: 7Last Post: 11-11-2014, 12:17 PM -
Make the sum of all elements of only one dimension of an array
By ana_carol in forum Advanced JavaReplies: 22Last Post: 12-16-2011, 05:26 PM -
Print the sum of elements, determined by zero elements
By Dimitri in forum New To JavaReplies: 3Last Post: 10-19-2011, 11:42 PM -
can i make a program to make keyboard and mouse idle or not responding for 10 second
By 3ammary in forum Advanced JavaReplies: 4Last Post: 07-23-2011, 08:08 PM
Bookmarks