A way to create new object instances in a loop?

I have an square matrix of String values.
Is there a way to take each row, make it into an object, and put the object in a new square matrix of objects?
Any ideas?

Do you mean something like this:Integer[][] foo = new Integer[5][5];
for (int i = 0; i < foo.length; i++) {
    for (int j = 0; j < foo.length; j++) {
foo[i][j] = new Integer(i + j);
}It's hard to guess what you want, why not post some code (use the code tags: Formatting tips)

Similar Messages

  • Reusing a variable from a new object instance

    I'm developing a stock list array for an assignment I'm currently working on. I've got most of it done, and it seems to be working for the most part, but I'm having trouble getting an array to accept individual variable entries created by new object instances in TestQ3.java.
    I think problem is because the variable itemCode in CraftItem.java is being overwritten by the creation of a new object instance in the TestQ3.java file. I've tested it and believe this to be true.
    I can add a String of my own choosing by using testArray.addCraftItemToStock(itemCode); line but I want to get the program to reuse the itemCode values that have already been created by the four new object instances in TestQ3.java. For example, I want to be able to add more instances of them to the testArray.
    As I'm still relatively new to Java programming, I'm wondering how to do this. I've tried several solutions but I'm not getting anywhere. I'd appreciate it if anyone has any ideas?
    Here's my code:
    TestQ3.java
    public class TestQ3 {
      public static void main(String args[]) {
        // creating a new StockItem array
        CraftStock testArray = new CraftStock(CraftStock.initialStockCapacity);
        // creating new object instance for Glue
        Glue gluePVA = new Glue("PVA Glue",250,"789012",2.50);
        // adds gluePVA item code to the testArray list
        // testArray.addCraftItemToStock(gluePVA.getItemCode());
        // creating new object instance for Card
        Card colouredCard = new Card ("Coloured Card","A3","654321",1.25);
        // adds coloured card item code to the testArray list
        // testArray.addCraftItemToStock(colouredCard.getItemCode());
        // creating new object instance for Glue
        Glue superGlue = new Glue ("Super Glue",25,"210987",1.50);
        // adds superGlue item code to the testArray list
        // testArray.addCraftItemToStock(superGlue.getItemCode());
        // creating new object instance for Card
        Card whiteCard = new Card ("White Card","A4","123456",0.50);
        // adds superGlue item code to the testArray list
        // testArray.addCraftItemToStock(whiteCard.getItemCode());
        // display complete stocklist
        testArray.displayCraftStockList();
        // this adds the itemCode from gluePVA to the array but
        // it comes out as the last itemCode entry 123456 rather than 789012
        // when I run the code. The problem may lie with variable itemCode
        testArray.addCraftItemToStock(gluePVA.getItemCode());
        // display complete stocklist
        testArray.displayCraftStockList();
    CraftItem.java
    public class CraftItem {
      // instance variables
      public static String itemCode;
      private double price;
      //private int stockCount;
      // constructor
      public CraftItem(String itemCodeValue, double itemPriceValue){
        itemCode = itemCodeValue;
        price = itemPriceValue;
        //CraftStock.addCraftItemToStock(itemCode);
        //stockCount++;
      // getter for itemCode
      public String getItemCode() {
        return itemCode;
      // getter for price
      public double getPrice() {
        return price;
      // setter for itemCode
      public void setItemCode(String itemCodeValue) {
        itemCode = itemCodeValue;
      // setter for price
      public void setPrice(double itemPriceValue) {
        price = itemPriceValue;
      // toString() value
      public String toString() {
        return "Item code is " + itemCode + " and costs " + price + " pounds.";
    Glue.java
    public class Glue extends CraftItem{
      // Instance variables
      private String glueType;
      private double glueVolume;
      // Constructor
      public Glue(String glueType, double glueVolume,
       String itemCodeValue, double itemPriceValue) {
            super(itemCodeValue, itemPriceValue);
            glueType = glueType;
            glueVolume = glueVolume;
      // getter
      public String getGlueType() {
        return glueType;
      // getter
      public double getGlueVolume() {
        return glueVolume;
      // setter
      public void setGlueType(String glueTypeValue) {
        glueType = glueTypeValue;
      public void setGlueVolume(double glueVolumeValue) {
        glueVolume = glueVolumeValue;
      // toString
      public String toString() {
        return glueType + ", " + glueVolume + "ml, item code is "
         + super.getItemCode() + " and costs " + super.getPrice() + " pounds.";
    Card.java
    public class Card extends CraftItem{
      // instance variables
      private String cardType;
      private String cardSize;
      // Constructor
      // added super(itemCodeValue, itemPriceValue) to call on CraftItem
      public Card(String cardTypeValue, String cardSizeValue,
       String itemCodeValue, double itemPriceValue) {
            super(itemCodeValue, itemPriceValue);
            cardType = cardTypeValue;
            cardSize = cardSizeValue;
      // getter
      public String getCardType() {
        return cardType;
      // getter
      public String getCardSize() {
        return cardSize;
      // setter
      public void setCardType(String cardTypeValue) {
        cardType = cardTypeValue;
      // setter
      public void setCardSize(String cardSizeValue) {
        cardSize = cardSizeValue;
      // toString
      // using super. to call on methods from superclass CraftItem
      public String toString() {
        return cardType + ", size " + cardSize + ", item code is "
         + super.getItemCode() + " and costs " + super.getPrice() + " pounds.";
    CraftStock.java
    public class CraftStock {
        public static int currentStockLevel;
        public static String[] craftStock;
        public static int initialStockCapacity = 10;
        public CraftStock(int initialStockCapacity) {
            currentStockLevel = 0;
            craftStock = new String[initialStockCapacity];
        public int currentStockLevel() {
            return currentStockLevel;
        public static void addCraftItemToStock(String itemCodeValue) {
            if(currentStockLevel == 10){
              System.out.println("Stock list full: cannot add new item code." +
                "\nPlease remove an item if you want to add a new one.");
            else{
            craftStock[currentStockLevel] = itemCodeValue;
            currentStockLevel++;
            System.out.println("Item added");
        public void removeCraftItemFromStock(String itemCode){
          findStockItem(itemCode);
          int i = -1;
            do {
                i++;
            } while (!craftStock.equals(itemCode));
    for (int j = i; j < currentStockLevel - 1; j++) {
    craftStock[j] = craftStock[j + 1];
    currentStockLevel--;
    System.out.println("Item removed");
    private int findStockItem(String itemCode){
    int index = 0;
    for(int i = 0; i < currentStockLevel; i++){
    if(craftStock[i].equals(itemCode)){
    index = i;
    break;
    else{
    index = -1;
    return index;
    public void displayCraftStockList() {
    if(currentStockLevel == 0){
    System.out.println("There are no items in the stock list");
    else{
    for(int i = 0; i < currentStockLevel; i++){
    System.out.println("Item at " + (i + 1) + " is " + craftStock[i]);
    Message was edited by:
    Nikarius

    An instance variable relates to an object. If you require a variable to be available across multiple objects of the same class then I suggest you declare a class variable using the static keyword in your declaration.
    HTH

  • How to create new OC4J instance in AS 10.1.3 with BC4J- and ADF-Libraries

    Hi
    I have done all the steps mentioned in this thread:
    How to create new OC4J instance in AS 10.1.3
    However, the new created OC4J instance obviously misses some libraries. If I deploy my Application to this OC4J I get an internal error: Class not found: oracle.jbo.JboException.
    The same Application runs well in the "home" Instance.
    What is the trick, to create a new OC4J instance, which more or less behaves the same way as the "home" instances (and especially has all the same libraries)?
    Thanks for your help
    Frank Brandstetter

    I encountered this last month. I definitely agree that it is a glaring omission to not have "Create Like" functionality when instantiating new containers. Here's my notes on the manual steps required after using createinstance to create the fresh container. Not too bad. I've been deploying ADF applications to the new container with no problems after this.
    ==============
    The default (home) OC4J container is pre-configured for ADF 10.1.3 applications; however, when $ORACLE_HOME/bin/createinstance is used to create additional containers, these containers are not configured automatically to host ADF 10.1.3 applications.
    I followed these manual steps:
    1. $ORACLE_HOME/j2ee/home/config/server.xml defines three shared libraries that "install" the needed JARs for Oracle ADF applications in your application server instance (container). Note that "install" does not necessarily mean available to applications (see Step 2). Copy the three shared library element definitions to the <application-server> element of your new container (in server.xml).
    <shared-library name="oracle.expression-evaluator" version="10.1.3" library-compatible="true">
         <code-source path="/usr2/oracle/as10130/jlib/commons-el.jar"/>
         <code-source path="/usr2/oracle/as10130/jlib/oracle-el.jar"/>
         <code-source path="/usr2/oracle/as10130/jlib/jsp-el-api.jar"/>
    </shared-library>
    <shared-library name="adf.oracle.domain" version="10.1.3" library-compatible="true">
         <code-source path="/usr2/oracle/as10130/BC4J/lib"/>
         <code-source path="/usr2/oracle/as10130/jlib/commons-cli-1.0.jar"/>
         <code-source path="/usr2/oracle/as10130/mds/lib/concurrent.jar"/>
         <code-source path="/usr2/oracle/as10130/mds/lib/mdsrt.jar"/>
         <code-source path="/usr2/oracle/as10130/jlib/share.jar"/>
         <code-source path="/usr2/oracle/as10130/jlib/regexp.jar"/>
         <code-source path="/usr2/oracle/as10130/jlib/xmlef.jar"/>
         <code-source path="/usr2/oracle/as10130/BC4J/jlib/adfmtl.jar"/>
         <code-source path="/usr2/oracle/as10130/BC4J/jlib/adfui.jar"/>
         <code-source path="/usr2/oracle/as10130/BC4J/jlib/adf-connections.jar"/>
         <code-source path="/usr2/oracle/as10130/BC4J/jlib/dc-adapters.jar"/>
         <code-source path="/usr2/oracle/as10130/ord/jlib/ordim.jar"/>
         <code-source path="/usr2/oracle/as10130/ord/jlib/ordhttp.jar"/>
         <code-source path="/usr2/oracle/as10130/jlib/ojmisc.jar"/>
         <code-source path="/usr2/oracle/as10130/jlib/jdev-cm.jar"/>
         <code-source path="/usr2/oracle/as10130/lib/xsqlserializers.jar"/>
         <import-shared-library name="oracle.xml"/>
         <import-shared-library name="oracle.jdbc"/>
         <import-shared-library name="oracle.cache"/>
         <import-shared-library name="oracle.dms"/>
         <import-shared-library name="oracle.sqlj"/>
         <import-shared-library name="oracle.toplink"/>
         <import-shared-library name="oracle.ws.core"/>
         <import-shared-library name="oracle.ws.client"/>
         <import-shared-library name="oracle.xml.security"/>
         <import-shared-library name="oracle.ws.security"/>
         <import-shared-library name="oracle.ws.reliability"/>
         <import-shared-library name="oracle.jwsdl"/>
         <import-shared-library name="oracle.http.client"/>
         <import-shared-library name="oracle.expression-evaluator"/>
    </shared-library>
    <shared-library name="adf.generic.domain" version="10.1.3" library-compatible="true">
         <code-source path="/usr2/oracle/as10130/BC4J/jlib/bc4jdomgnrc.jar"/>
         <code-source path="/usr2/oracle/as10130/BC4J/lib"/>
         <code-source path="/usr2/oracle/as10130/jlib/commons-cli-1.0.jar"/>
         <code-source path="/usr2/oracle/as10130/mds/lib/concurrent.jar"/>
         <code-source path="/usr2/oracle/as10130/mds/lib/mdsrt.jar"/>
         <code-source path="/usr2/oracle/as10130/jlib/share.jar"/>
         <code-source path="/usr2/oracle/as10130/jlib/regexp.jar"/>
         <code-source path="/usr2/oracle/as10130/jlib/xmlef.jar"/>
         <code-source path="/usr2/oracle/as10130/BC4J/jlib/adfmtl.jar"/>
         <code-source path="/usr2/oracle/as10130/BC4J/jlib/adfui.jar"/>
         <code-source path="/usr2/oracle/as10130/BC4J/jlib/adf-connections.jar"/>
         <code-source path="/usr2/oracle/as10130/BC4J/jlib/dc-adapters.jar"/>
         <code-source path="/usr2/oracle/as10130/ord/jlib/ordim.jar"/>
         <code-source path="/usr2/oracle/as10130/ord/jlib/ordhttp.jar"/>
         <code-source path="/usr2/oracle/as10130/jlib/ojmisc.jar"/>
         <code-source path="/usr2/oracle/as10130/jlib/jdev-cm.jar"/>
         <code-source path="/usr2/oracle/as10130/lib/xsqlserializers.jar"/>
         <import-shared-library name="oracle.xml"/>
         <import-shared-library name="oracle.jdbc"/>
         <import-shared-library name="oracle.cache"/>
         <import-shared-library name="oracle.dms"/>
         <import-shared-library name="oracle.sqlj"/>
         <import-shared-library name="oracle.toplink"/>
         <import-shared-library name="oracle.ws.core"/>
         <import-shared-library name="oracle.ws.client"/>
         <import-shared-library name="oracle.xml.security"/>
         <import-shared-library name="oracle.ws.security"/>
         <import-shared-library name="oracle.ws.reliability"/>
         <import-shared-library name="oracle.jwsdl"/>
         <import-shared-library name="oracle.http.client"/>
         <import-shared-library name="oracle.expression-evaluator"/>
    </shared-library>
    2. To make the necessary ADF and JSF support libraries available to your deployed ADF application, the default application (that your ADF application and the majority of applications should inherit from) should explicitly import the shared library in the <orion-application> element of $ORACLE_HOME/j2ee/<your container>/config/application.xml.
    <imported-shared-libraries>
         <import-shared-library name="adf.oracle.domain"/>
    </imported-shared-libraries>
    Note: the adf.oracle.domain shared library imports several other shared libraries including oracle.expression-evaluator.

  • Different ways to create an object

    Hi All,
    I am a new bie to java programming. I know the way to create an object for a class will be something like
    A b = new A(); // A is the class name and b is the object name.
    But i am not sure what the following code means, I know it is also creating an object but how and why in that manner.
    CaptureSearchForm userBean = (CaptureSearchForm) form;
    A b = (A) c;
    If b is the object name, then what is c here?Can anyone please explain me in detail.
    Also,
    java.util.List pageList = new ArrayList();
    Why should we give in the above manner? what does it mean?
    Thanks in advance....,,,,

    auto wrote:
    But i am not sure what the following code means, I know it is also creating an object but how and why in that manner.
    CaptureSearchForm userBean = (CaptureSearchForm) form;This does not create an object. It takes the value in the reference variable foram and copies it into the refernce variable userBean, so that userBean and form both point to the same object. The (CaptureSearchForm) is called a cast. It tells the compiler that even though form may not be declared to be of type CaptureSearchForm or a subclass, you the programmer know that the object it points to will be a CaptureSearchForm or a subclass, and to treat it as such. If at runtime this is not the case, you'll get a ClassCastException.
    A b = (A) c;
    If b is the object name, then what is c here?Can anyone please explain me in detail. b is not the object name. Objects do not have names. b and c are both variable names.
    Also,
    java.util.List pageList = new ArrayList();
    Why should we give in the above manner? what does it mean?It's known as programming to the interface. On the LHS, you're saying that pageList must point to an object that implements List. You don't cae if it's an ArrayList or LinkedList or something else. It's a way to decouple your code from the specific implementations of the types it uses.

  • Creating New Entity Instances within OPA

    This is another one that I think I know the answer to, but I think it is best to confirm.
    In prior versions, it was not possible to create entity instances within RuleBurst/Haley Office Rules. Is that still the case in OPA?
    For example, my rules are determining the status of a case and the reason(s) why that status was determined. The case status may be Denied and the reasons may be "invalid customer Id", "expenses to income ratio too high", "primary customer not employed long enough", etc. I want to return all the reasons for the status. While the list of reasons is pre-determined, the ones that apply to a particular case are dynamic, as any, but not all can apply.
    Given this situation using a database, I would create an instance of reason for each applicable one and link it to the case. In the past, with OPA's predecessor(s), it was not possible to create new instances from within. They either had to all be passed into the rulebase or a list of all allowable reasons attributes had to be created and then set to true for the ones that applied.
    My preference is to create the instances inside OPA. Is that functionality provided in the current version?
    Thanks,
    Terry

    Hi Terry,
    Michael is correct that you can't write rules at design time which will dynamically create new entity instances at runtime. However, perhaps the new inferred relationships functionality in v10 could address what you're trying to do.
    You can write rules which conclude membership of an inferred relationship. So you might always have, say, 10 instances of 'the reason' in every case, but as for which of those instances apply in any particular case, it depends on the details of the case. You could use an inferred relationship to collect up the entity instances which apply in the case.
    First you'd need to set up a regular one-to-many relationship to instantiate the 10 instances at runtime - this would be done in the usual way. Then you'd also need to set up an inferred relationship and write rules to conclude the members of the inferred relationship. The instances which are members of the inferred relationship are then effectively the list of entity instances you wanted to create in your example above.
    Have a look at this OPM Help article: http://www.oracle.com/technology/products/applications/policy-automation/help/opm10_1/Content/Rules%20using%20entity%20instances/Reason_about_relship_between_2_entities.htm
    Cheers,
    Jasmine

  • Creating dynamic object instance names

    If I have a class such as ...
    class NewDevice
    I would create a new instance of that object by calling 'NewDevice' as ....
    NewDevice nd = new NewDevice();
    Suppose I don't actually know how many device I need before I read a file in and then subsequently create a new object instance. I could have a long list of variable name i.e. nd1, nd2, nd3 etc but that would be messy and I would be sure to run out.
    My Question..........
    How do I create object instances with unique names 'on-the-fly' so to speak
    Thanks

    Here's an example that allows you to build up a list of NewDevice instances, see how many there are and get them back by their index in the list:
    public class MyClass
      List newDeviceList;
      public MyClass()
        newDeviceList = new ArrayList();
      public void addNewDevice(NewDevice newDevice)
        newDeviceList.add(newDevice);
      public int getNewDeviceCount()
        return newDeviceList.size();
      public NewDevice getNewDevice(int idx)
        return (NewDevice)newDeviceList.get(idx);
    }Hope this helps.

  • What is the diffrence between extends and creating new object?

    HI ALL,
    what is the diffrence between extends and creating new object?
    meaning
    class base{
    class derived extends base{
    class base{
    class derived {
    derived(){
    base var = new base();
    can u people tell me diffence from the above examples.
    THANKS.
    ANANDA

    When you create a new object you have to supply the class to which that
    object belongs. A class can extend from another class. If it does so
    explicitly you can define the 'parent' class from which the class extends.
    If you don't explicitly mention anything, the class will implicitly extend
    from the absolute base class named 'Object'.
    Your example is a bit convoluted: when you create a Derived object,
    its constructor creates another object, i.e. an object from the class from
    which the Derived class extends.
    Extending from a class and creating an object don't have much in common.
    kind regards,
    Jos

  • Is there a way to create new events on the new iPhoto app?

    Is there a way to create new events on the new iPhoto app?  I seem to only be able to create albums.  I would really like the app to allow me to do all the same things that I was able to do on my Mac.  I would create events and then sync to all devices.  Can someone please instruct me on how to create new events from the photos imported from the photo stream.
    Thanks for all the help!

    The iPhoto for iOS seems to be aimed at working on photos then sharing them to social media sites or to iCloud for sharing there. iPhoto for iOS does not perform many of the organizing tasks that iPhoto on your Mac does. Many people expected that there would be more capabilities in iPhoto for iOS that would allow it to work more closely with iPhoto on your computer but this is not the case. They are separate apps.

  • Problem in creating new objects in ABAP workbench

    Hi ,
        I am getting error in a newly installed SAP system when try to create new objects in ABAP workbench. The error is like'No changes for the user allowed'.
    Can you tell me what the error is here? What can be done for this so that I can create new object.
    Thanks,
    Manas

    Hi,
    Run tcode SU01. (Provided if u hav authorization to run this Tcode)
    Enter SAP* as user and click on the Copy button.
    Enter the name for your new user in the dialog box and click Continue
    Enter a password for your new user.
    Goto Profile sheet and adjust the profiles to be SAP_ALL and SAP_NEW.
    Save the user and logon with it.
    Now you'll be able to do your changes.
    Reward Points if useful.
    Regards
    Rose
    Edited by: Rose Preethi on Mar 31, 2008 5:20 PM

  • How to create new object key in BDS?

    Hello,
    I need to create custom class in BDS (OT type) and object key for it.
    In this forum (and in the whole Internet) I found information only about custom class. However there's nothing about object key.
    How could I create new object key in BDS class?
    Great thanx in advance!

    Hi Max,
    you can create BOR object in business object repository, Transaction SWO1, SWO2, search documentaion for BOR obkect.
    Regards,
    Clemens

  • All my photos on my phone are in 1 album. Is there a way to create new albums and move some pictures to them?

    All my photos on my phone are in one album. Is there a way to create new albums and move some of them?

    With photos transferred from your computer, you create the albums or folders on your computer.
    If you manually manage photo storage on your computer, create a parent folder that will store the named folders of photos you want transferred to your iPhone. Place the named folders of photos in this parent folder and select the parent folder under the Photos tab for your iPhone sync preferences with iTunes followed by a sync. The folders of photos inside of the parent folder on your computer's hard drive will be transferred to your iPhone as separate albums. To add an additional album of photos to your iPhone, place the folder of photos in the parent folder followed by a sync. To remove an album of photos from your iPhone, move the folder of photos outside of the parent folder followed by a sync.

  • KEA0 what is the best way to create new Operating concern

    Hello :
    Please advise
    1. what is best way to create new OP concern
        copy from template or create data structure from scratch?
    2. I try to copy from OP concern = IDEA but when click change DATA STRUTURE -I see only CE1xxx but I not see CE2xxxx, CE3xxxx, CE4xxxx ...
       pls advise - how to? can I change data structure on CE2, CE3....
    Thx in advance.
    Manthana

    If your data structure will be the same then do a copy. if the data structures are different then create from scratch ( or modify after copy).  Copy saves time so you don't have to start from scratch.

  • Resuse existing object (Sp,tables etc)or create new object if that is possible?

    Hello Everyone,
    Is it a good practice to create new objects (stored procedures, tables etc.) or modify and reuse the existing object if that can be done?
    Regards
    Regards

    If you need simple add a new column to the SELECT statement so there is no need to create a new stored procedure/view for this
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Problem when creating new Objects in ESR

    Hi ,
    When i am trying to create new objects in ESR it is no allowing me to do,i have developed around 80 interfaces as of nowmsuddenly this eeror i getting,anyone experienced this kind of issue.
    *You cannot create new objects since the system is not the original system of the software component version*
    You cannot create new objects since the system is not
    the original system of the software component version (NOT_ORIGINAL_NO_CREATE)
    MESSAGE ID: com.sap.aii.ib.server.oa.rb_all.NOT_ORIGINAL_NO_CREATE
    Regards,
    Raj

    Hi Raja,
    I am new to SAP PI. So i dunno much regarding SAP PI. Hence i am getting same error that not able to create objects in SWCV. I read this discussion but i dunno where to select the 'Modifiable & Original' options, so that i can enable the Objects. Can you please guide me?
    Thanks,
    Amarnath

  • Any way to create new albums

    Is there any way to create new photo albums and move pictures in to them??

    If you are on a mac, you can create new albums in iphoto.
    Move the photos you want into the new albums and then sync them to the iphone.
    If you are on a pc, you can create a new folder on your computer then create sub folders.
    Add photos you want to the sub folders.
    Now sync the main folder to the iphone and the sub folders will show up as new albums on the iphone.
    There is not a way to create albums or move photos on the iphone.
    Hope this helps.

Maybe you are looking for