Object references and array of integers

Hello,
Taking some java test, I came across the following question:
Given the below (UML) diagram, how many of the ClassA attributes will be object references when this class is implemented in the Java language?:
       ClassA                                         <<enumeration>>   
                              ------------------->         Enum1
      var1 : int                                              
      var2 : String                                         Elem1
      var3 : int[]                                          Elem2
      var4 : float                                          Elem3
      var5 : Double                                         Elem4
      var6 : Enum1   I answered 3, but the correct answer was 4. The one which I did not include was var3. Why will var3 be an object reference?
Thank you,
Mihai

That is true, my mistake. Arrays are object references (you do indeed instantiate an array by using the new keyword), but I was thrown off by what the array holds, namely primitive types, not object references.
Thank you,
Mihai

Similar Messages

  • Java - Instance variable that can reference an array of integers?

    Hello,
    I have the following question in my assignment:
    Your first task is to declare a private instance variable called cGroups that can
    reference an array of integers. You should then write a constructor for GameN. This should
    take a suitable array as its argument which should be used to initialise cGroups.
    In order to test your code for declaring and initialising cGroups, you should execute
    the following code
    int[] coin = {2, 8, 5};
    GameN aGame;
    aGame = new GameN(coins);
    and I have complete the code below but it's not working. maybe I'm reading it wrong or
    not understandin something. Could someone correct it? or put me on the right lines
    private int[] cGroups = new int[]
    public GameN(int group1, int group2, int group3)
    super();
    this.cGroups = {group1, group2, group3};
    }

    ShockUK wrote:
    I've changed it to
    private int[] coinGroups = new int[] {1};
    public Nim(int group1, int group2, int group3)
    super();
    int[] coinGroups = {group1, group2, group3};
    }But I still get the same error "Constructor error: Can't find constructor: Nim( [I ) in class: Nim"
    Look at the line that error is pointing at. You're trying to use a constructor that doesn't exist. This is not a problem with creating an array.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Problems launching Object Manager and Array Manager in SSGD 4.20.983

    Hi,
    I have just installed SSGD 4.20.983 in a server which is running Solaris 10. The language of this server is Spanish.
    When I access to the webtop, I 'm not be able to launch the applications Object Manager and Array Manager.
    When I try to launch them, in the details box appears "Contrase�a" and them the timeout expires. Contrase�a is the same that password in Spanish.
    Anyone can help me?
    Regards,
    Diego

    Do you have any logfiles which look like : execpePID_error.log?
    These files should contain more information.
    Also take a look at the following section of the Administration Guide: [http://docs.sun.com/source/820-6689/chapter4.html#d0e21816]
    Especially the part '+Increasing the Log Output+'
    - Remold

  • Differences between using a Object Reference and the Object itself

    Example:
    public class Myclass
    //difference between
    Myclass myobj;
    //and
    Myclass myobj = new Myclass();
    can anyone help me?

    Both lines you showed declare an object reference.
    The first one is not explictely assigned a value and
    is thus implicetly assigned the null reference (= a
    reference pointing to no object). The latter is
    initialized with an reference to the newly created
    Object (new Myclass()).
    They're both given a value of null first.
    The second one is then given a value that points to that object that was created.
    If they were inside a method, then the first one's value would be undefined.

  • Problem using Oracle Object Types and Arrays.

    I'm currently trying to work with oracle object types in java and I'm running into some issues when trying to add an item to an array.
    The basic idea is that I have a header object and a detail object (both only containing an ID and a description). Inside of my java code I'm trying to add a new detail line to the header that has been retrieved from the database.
    Here's what I'm working with.
    --Oracle Objects:
    CREATE OR REPLACE TYPE dtl_obj AS OBJECT
        detail_id INTEGER,
        header_id INTEGER,
        detail_desc VARCHAR2(300)
    CREATE TYPE dtl_tab AS TABLE OF dtl_obj;
    CREATE OR REPLACE TYPE hdr_obj AS OBJECT
        header_id INTEGER,
        src VARCHAR(30),
        details dtl_tab
    CREATE TYPE hdr_tab AS TABLE OF hdr_obj;
    /--Java test methods
         public static void main(String[] args) throws SQLException,
                   ClassNotFoundException
              // Initialize the objects
              Test t = new Test();
              t.connect(); //Connects to the database
              //The oracle connection will be accessible through t.conn
              // Create the oracle call
              String query = "{? = call get_header(?)}";
              OracleCallableStatement cs = (OracleCallableStatement) t.conn.prepareCall(query);
              cs.registerOutParameter(1, OracleTypes.ARRAY, "HDR_TAB"); //Register the out parameter and associate it with our oracle type
              int[] hdrs = { 240 }; //we just want one for testing.
              ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(
                        "ARRAY_T", t.conn);
              oracle.sql.ARRAY oHdrs = new ARRAY(descriptor, t.conn, hdrs);
              cs.setARRAY(2, oHdrs); //Set the headers to retrieve
              // Execute the query
              cs.executeQuery();
              try
                   ARRAY invArray = cs.getARRAY(1);
                   // Start the retrieval process
                   Class cls = Class.forName(Header.class.getName());
                   Map<String, Class<?>> map = t.conn.getTypeMap();
                   map.put(Header._SQL_NAME, cls);
                   Object[] invoices = (Object[]) invArray.getArray();
                   ArrayList<Header> invs = new ArrayList(
                             java.util.Arrays.asList(invoices));
                   if (invs != null)
                        for (Header inv : invs)
                             System.out.println(inv.getHeaderId() + " " + inv.getSrc());
                             t.addDetail(inv, "new line");
                             for (Detail dtl : inv.getDetails().getArray()) // Exception thrown here
    //                              java.sql.SQLException: Fail to construct descriptor: Invalid arguments
    //                              at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
    //                              at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
    //                              at oracle.jdbc.driver.DatabaseError.check_error(DatabaseError.java:861)
    //                              at oracle.sql.StructDescriptor.createDescriptor(StructDescriptor.java:128)
    //                              at oracle.jpub.runtime.MutableStruct.toDatum(MutableStruct.java:109)
    //                              at com.pcr.tst.Detail.toDatum(Detail.java:40)
    //                              at oracle.jpub.runtime.Util._convertToOracle(Util.java:151)
    //                              at oracle.jpub.runtime.Util.convertToOracle(Util.java:138)
    //                              at oracle.jpub.runtime.MutableArray.getDatumElement(MutableArray.java:1102)
    //                              at oracle.jpub.runtime.MutableArray.getOracleArray(MutableArray.java:550)
    //                              at oracle.jpub.runtime.MutableArray.getObjectArray(MutableArray.java:689)
    //                              at oracle.jpub.runtime.MutableArray.getObjectArray(MutableArray.java:695)
    //                              at com.pcr.tst.DetailTable.getArray(DetailTable.java:76)
    //                              at com.pcr.tst.Test.main(Test.java:91)
                                  System.out.println(dtl.getDetailDesc());
              catch (Exception ex)
                   System.out.println("Error while retreiving header");
                   ex.printStackTrace();
              public void addDetail(Header hdr, String desc) throws Exception
              if (hdr == null)
                   throw new Exception("header not initialized");
              // Convert the current list to an ArrayList so we can easily add to it.
              ArrayList<Detail> dtlLst = new ArrayList<Detail>();
              dtlLst.addAll(java.util.Arrays.asList(hdr.getDetails().getArray()));
              // Create the new detail
              Detail dtl = new Detail();
              dtl.setDetailDesc(desc);
              // add the new detail
              dtlLst.add(dtl);
              Detail[] ies = new Detail[dtlLst.size()];
              ies = dtlLst.toArray(new Detail[0]);
              DetailTable iet = new DetailTable(ies);
              hdr.setDetails(iet);
         }I know its the addDetail method causing the issue because if I comment out the t.addDetail(inv, "new line"); call it works fine.
    Message was edited by:
    pcristini

    Oracle® Database Object-Relational Developer's Guide
    Also note that object relational database design is often less performant and scalable than relational. It is not very often used in production environments.
    However, the object orientated programming feature that is provided with Oracle object feature set are used and can make development and interfaces a lot easier.
    So in a nutshell. Say no to ref and nested table columns. Say yes to most of the other object features. IMO of course...

  • After serialize a object what will be the value of reference and primitive

    After serialize a particular object what will the value its object references and primitives ???
    please go through the following scenario
    import java.io.*;
    class Dog implements Serializable{
         String dogString = "haiHai";
         int dogSize = 555;
         public String toString(){
              return "This is Object Man";
    class MyTestSerial
         Dog d = new Dog();
         MyTestSerial(){
                   try{
                        System.out.println("Before Serialization Dog object is : " +d);
                        System.out.println("Before Serialization d.dogSize : " +d.dogSize);
                        FileOutputStream fis = new FileOutputStream("MyTest.ser");
                        ObjectOutputStream obs = new ObjectOutputStream(fis);
                        obs.writeObject(d);
    obs.writeInt(d.dogSize);
    obs.writeObject(d.dogString);
                        System.out.println("After Serialization Dog object is : " +d);
                        System.out.println("Before Serialization d.dogSize : " +d.dogSize);
                   }catch(Exception e){
                   System.out.println(e);
         public static void main(String[] args) { MyTestSerial t = new MyTestSerial();     }
    In the above MyTestSerial class am serializing Dog object. After executing this obs.writeObject(d); the dog object will serialize without any problem.
    Now, once i try to print the dog object and dogString it should print the null value right ??
    and its primitive dogSize in the Dog class also print the value zero right??
    But am not getting those results. What mistake am doing here???
    Generally What will happen when we serialize a object or primitive value. After this what is the value of these types??
    Can any one a give the solution???
    Regards
    Dhinesh Kumar R

    Serializing merely copies the object data to the stream, the content is unaffected.

  • Adding user-created objects to an Array

    I would be grateful if anyone can help me. I have created the following class:
    import java.util.*;
    * Created on 08-Dec-2005
    * @author Hussein Patwa
    public class room {
        public String roomName;
    // String to hold the room name
        public static void main(String[] args) {
        String roomName;
        // Temp string to hold room name
        LinkedList objectqueue = new LinkedList();
        // Queue implementation to hold list of objects in room
        LinkedList stack = new LinkedList();
        // Stack implementation to hold objects held by user
    public void enterRoomName(String roomName) {
        // Method to allow entering of the room name
        this.roomName = roomName;
        // Assignment the room name to the roomName field
    public void viewRoomName() {
        // Method to allow the viewing of the room name
        System.out.println("This is the " + roomName + " ");
        // Print the room name
    }I also have a main class:
    import java.util.*;
    * Created on 08-Dec-2005
      * @author Hussein Patwa
    public class start extends room {
        public static void main(String[] args) {
      String gameName = "PatwaMaze";
      // Field to hold the game name
      room[] roomList = new room[6];
      // Create a new array to hold the rooms
    public void startGame() {
    roomList.add["Kitchen"];
    roomList.add["Parlour"]
    roomList.add["Lounge"]
    roomList.add["Stairs"]
    roomList.add["Chamber"]
    roomList.add["Study"]
    }I want to create an array of room objects, or would it be more correct to say object references, and then have their labels as the room name, which would be stored in that room's roonName field. So then I can iterate through the list, and print out each room's roomName field thus giving a list of the rooms. So (and I hope this is making sense), I need to add the rooms to the array, set each room's rromName field and then iterate through it. But I'm not sure of the syntax to add the room's name and the array index.
    BTW, I have done quite a bit of searching for this, as well as looked through several texts, so I am posting here because i'm not sure where to go next.
    Thanks.
    Hussein.

    Short answer: There's no add method. That woul be in a Collection.
    http://java.sun.com/docs/books/tutorial/collections/
    For an array, it's arr[0] = something;
    arr[1] = somethingElse;
    / / etc.

  • Expected object reference found execution

    I have a .NET DLL that has a method that takes as a by reference parameter an object of type NationalInstruments.TestStand.Interop.API.Execution. In TestStand 4.2.1 this worked fine if I passed it RunState.Execution.
    Now in TestStand 2010 I get an error in TestStand that the method expected an object reference, but found an execution. An execution is what I want is what the method is describing. So, why does this not work?
    Anyone have any ideas?
    Thanks.
    Solved!
    Go to Solution.

    Hi Skeptical,
    This is a known backwards compatibility issue introduced in TestStand 2010 and will be fixed in a future release.
    That said, it doesn't really make sense for the parameter to be byref (i.e. in/out) in this case because the Execution interface is already a reference data type. Thus, passing it byref implies that the method has the possibility of replacing the object which RunState.Execution points to with a different Execution object which most likely is not something the method would ever do.
    So as a workaround you can do one of the following:
    1) Change the prototype of the method (or add a new overload) to take the execution parameter by value (i.e. in only), which is likely what the author of the code really intended anyway.
    Or
    2) Create a local variable of type Object Reference, and assign RunState.Execution to it before your call to the method, and then pass the local variable for the byref parameter.
    Please let us know if you have any questions or if the workarounds are not sufficient for you.
    Hope this helps,
    -Doug

  • Pass object reference from TestStand to C#

    Hi,
    I have created a GUI in .NET which i invoke in TestStand (through a custom step type). User can enter a object reference teststand variable in the UI input expression box. So i need to get the object value in that variable and use it to call some .net functions. To get the values from expression box of UI and put in TestStand step variable i use:
             PropertyObject.SetValInterface("Step.TestStationObj", 0, tsexprTestStationObj.DisplayText.Trim()); To check the value in the step variable if i do:
             MessageBox.Show("TestStation obj after setting:",PropertyObject.GetValInterface("Step.TestStationObj",0).ToString());
    But i do not get any value. Guess it is null. Is this a correct way? My intension is to get the value corresponding to a teststand object reference and pass it to C#. The C# UI control is of type NationalInstruments.TestStand.Interop.UI.Ax.AxExpressionEdit

    Thanks Andy.
    I still get the error when i am trying to pass the object created from C# to Teststand. I have explained what i am trying to do. Kindly requesting your assitance on this issue.
    I have 2 classes in C# (code given below), I am trying to pass the object of "Counter" (c1) class from the "Mainfrm" to teststand. In teststand(counter.seq), I am trying to access the function "GetCount() and SetCount()". I have attached the snapshot of the error that i get from teststand.
    Class Counter
        private int count;
        public int GetCount ()
           return (count);
        public void SetCount(int _count)
           count = _count;
    Class Mainfrm : Form
        public Counter c1;
            private void Mainfrm (object sender, EventArgs e)
                InitializeComponent();
                axApplicationMgr1.Start();
                mEngine = axApplicationMgr1.GetEngine();
                currentFile = axApplicationMgr1.OpenSequenceFile(@"Counter.seq");
                pobj = mEngine.NewPropertyObject(NationalInstruments.TestStand.Interop.API.PropertyValueTypes.PropValType_Container, false, "", 0);
                pobj.NewSubProperty("Parameters.ObjRef1", NationalInstruments.TestStand.Interop.API.PropertyValueTypes.PropValType_Reference, false, "", 0);
                pobj.SetValInterface("Parameters.ObjRef1", 0, (object)c1);
                mExecution = mEngine.NewExecution(currentFile, "MainSequence", null, false, 0, pobj, null, null);
    Attachments:
    ErrorFromTestStand.JPG ‏28 KB

  • A simple teststand applicatio​n passing object reference to C#

    Hi,
     I have a  .NET application written in C# which has a UI with  NationalInstruments.TestStand.Interop.UI.Ax.AxExpressionEdit controls. This UI is invoked by a custom step in TestStand. One of the values, entered by user in the UI is a object reference variable created in a previous step. I need to store the values entered in the UI during the edit mode of the step, into the TestStand Step variables. And during the run mode i use these values to execute the logic in C#. 
    The problem is during edit time, the object reference variable, entered in the UI, has no value. It is null. So there is no use storing it at edit time. During the runtime i am trying to retrieve the value of the object reference variable using GetValInterface(...) and GetValIDispatch(..) methods of PropertyObject. But the object returned to C# is of type System.__COMObject wherease in TestStand that object reference is of type .NET.
    I don't know how a .NET object reference is converted to COM object when it is returned to .Net function.
    Also is there any other method to send this object reference variable's (whose value is '.NET' in previous step itself) value to .NET as a .NET object only so that i can typecast to appropriate type and start using.
    Thanks.
    Please let me know if anything is not clear.
    I have attached the .Net project, .ini file for the custom step and a example sequence file.
    Attachments:
    CCustomStepObj.zip ‏23 KB

    Hello Shivapriya,
    The example you've sent doesn't compile. And it without it I'm affraid I do not understand the problem you're describing.
    You've given references to libraries that you've not attached with your files.
    For the C# I see these are the
    IADCore.dll
    InstrimentInterfaces.dll
    TestStand also seems to want to reach for the assembly named TestSystem.dll.
    I can only tell you that I have used successfully in the past the Variables in TestStand to hold .NET object references, and call methods on them and I experienced nothing similar that you describe, but I don't quite follow what is the problem here, as I can't use the example. 
    I would appriciate if you cold narrow down the example to 1 dll or something where the problem occurs and than resend it.
    Regards,
    Maciej 
    Message Edited by Mac671 on 09-28-2009 02:59 AM

  • Passing object references via methods

    Why is the JFrame object not being created in the following code:
    public class Main {
      public static void main(String[] args) {
        Main main = new Main();
        JFrame frame = null;
        main.createFrame(frame);  // <-- does not create the "frame" object
        frame.pack();
        frame.setVisible(true);
      private void createFrame(JFrame frame) {
        frame = new JFrame("createFrame");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }Thanks.

    These explanations are great; real eye openers.
    OK. This could be a "way out in left field" question. I am just starting out with Java. But I want to ask:
    Objects are stored in the heap?
    Object references and primitives are stored on the stack?
    Adjusting heap size is straight-forward. A larger heap can store more/larger objects. What about stack sizes?
    C:\Dev\java -Xss1024k Main
    I assume this refers to method's stacks. But, what about object scoped, and class scoped, object references?
    public class Main {
      private static List list = new ArrayList(); // class scoped
      private JFrame frame = new JFrame();  // object scoped
      public static void main(String[] args) { ...... }
      private void createFrame() { .... }
    }How is the reference to list and frame stored, with regard to memory management?
    Do objects have stacks?
    Do classes have stacks?
    If not, how are the list and frame references stored (which helps me understand reference scoping).
    Would the overflow of a method stack (ex. via recurssion) also overflow the method's object and the method's class stacks?
    If these questions are stupid, "out of left field", don't matter, etc. Just ignore them.
    But the knowledge could help me avoid future memory related mistakes, and maybe pass a "Java Certified Developer" exam?
    My original question is already answered, so thanks to all.

  • Object Reference Casting Doubt

    class A extends Object{
      //this class is empty
    }//end class A
    //===================================//
    class B extends A{
      public void m(){
        System.out.println("m in class B");
      }//end method m()
    }//end class B
    //===================================//
    class C extends Object{
      //this class is empty
    }//end class C
    //===================================//
    public class Poly02{
      public static void main(
                            String[] args){
        Object var = new B();
        //Following will not compile
        //var.m();
        //Following will not compile
        //((A)var).m();   
        //Following will compile and run
        ((B)var).m();
      }//end main
    }//end class Poly02Why cant I do var.m();?
    Bacause var is an Object Reference and a new Object of type B itself is created. So run time polymorphism should hold good and I should be able to access [b]m() without any cast..
    Please tell me the best place to learn Object Reference Casting Fundamentals.

    Why cant I do var.m();?
    Bacause var is an Object Reference and a new
    Object of type B itself is created. So run time
    polymorphism should hold good and I should be able to
    access [b]m() without any cast..It doesn't matter what var is referencing. You should only look at the reference type. It's Object, and Object does not contain a m() method.
    Kaj

  • Reconstructing Object references

    Im attempting to serialize an object which contains other object references, and then deserialize it back into a difference instance of the same java application. How can I reconstruct the object references inside my serialized object so that they once again point to the correct objects? I dont want to use any corba apis or anything like that, there must be some java native way of doing this (finding objects ie name resolution)...
    Thanks in advance

    You have to read in the serialized object and cast it to the serialized object type.
    //Guid is how I am differentiating the objects
    try
    ObjectInputStream in = new ObjectInputStream(new FileInputStream(guid));
    YourClass yc = (ObjectMaker)in.readObject();
    if (yc.equals(null))
         System.out.println("Object Bean not found");
         return;
    in.close();
    frame.getContentPane().add(yc,BorderLayout.CENTER);
    This restores the object back to its type.
    If you are using Drag and Drop, I would suggest creating a new constructor that accepts the bean name, and reading the object from within it's class. You can then restore the models from the constructor
    hope this helps,
    mattrock

  • The truth about objects, references, instances and cloning (Trees and Lists

    Hello
    As a few of you may have know from my postings over the past few weeks, ive been building my first real java ap and trying to learn along the way, hitting a few snags here and there.
    One main snag i seem to have been hitting a fair bit is objects and instances, im kinda learning on how they work and what they mean but as a php programmer it seems to be very different.
    as pointed out to me if you have objectA=objectB then in php you have two objects that share the same value but in java you have still one object value and one object pointing to the value.
    sooo my first question is
    if i have this
    Object objA=new Object()
    Object objB=objA()then object A creates a new memory allocation for the object data right? and object B is simply a reference to the object A memory allocation right?
    so therefore there is no instance of objectB? or is there an instance of object B but it just takes up the same memory allocation as object A?
    anyway, what is the point of being able to say objB=objA what can that be used for if not for making a copy of an object (i understand now that it doesnt copy an object)
    My second question (which i think i actually understand now, but im posting it to see if the answers may help others)
    If i have a List structure (e.g. arraylist) then when i add a datatype such as a treemap does it not add the changed treemap, ill try and explain with code
    ArrayList mylist=new ArrayList()
    Treemap myTree=new Treemap()
    myTree.put("hello","howdy");
    myTree.put("bye","cya");
    mylist.put(myTree);
    System.out.println(mylist.toString());
    myTree.put("another","one");
    mylist.put(myTree);
    System.out.println(mylist.toString());now to be honest ive not actually tried that code and it may actually procude the right results, but from my experience so far that similar sort of thing hasnt been working (by the way i know the above code wont compile as is :p)
    anyway what i assume is that will output this
    [Hello,howdy,bye,cya] <<this is the first system out
    [Hello,howdy,bye,cya,another,one  <<this is the second system out
    Hello,howdy,bye,cya,another,one] <<this is the second system out
    where it should produce this
    [Hello,howdy,bye,cya,
    Hello,howdy,bye,cya,another,one]
    Why when I update the treemap does the arraylist change, is this because the thing that is being put in the array list is infact not an object but simply a reference to an object?
    thanks for everyones help so far :)

    as pointed out to me if you have objectA=objectB then
    in php you have two objects that share the same value
    but in java you have still one object value and one
    object pointing to the value.Some years ago, I built a small website managing data saved in an XML file using PHP. Being used to Java, I used an OO approach and created classes managing data structures and having setter/getter methods. The fact that PHP did actually create a copy of any object being passed as and argument made me crazy. This way, I wasn't able to reach the same instances from several different places in my code. Instead, I had to put a certain operator ("&" I think) before any reference to force PHP not to make a copy but pass the reference. I also found a note on the PHP site saying that copying was faster than passing the reference, which I actually couldn't believe. If I'm not wrong, they changed the default behaviour in PHP5.
    if i have this
    Object objA=new Object()
    Object objB=objA()then object A creates a new memory allocation for the
    object data right? and object B is simply a reference
    to the object A memory allocation right?The statement "new <Class>" allocates memory. The reference itself just takes up a few bytes in order to maintain some administrative data (such as the memory address). References are basically like pointers in C, though there's no pointer arithmetics and they can't point to any arbitrary place in memory (only a legal instance or null).
    so therefore there is no instance of objectB? or is
    there an instance of object B but it just takes up
    the same memory allocation as object A?There is an instance of objectB, but it's just the same instance that objectA is pointing at. Both references objectA and objectB contain the same memory address. That's why they'd produce a result of "true" if compared using the "==" operator.
    anyway, what is the point of being able to say
    objB=objA what can that be used for if not for making
    a copy of an object (i understand now that it doesnt
    copy an object)Sometimes you don't want to make a copy, as 1) it consumes more memory and 2) you'd lose the reference to it (making it more difficult to tell what instance is actually accessed). If there was no way to pass a reference to an object into a method, methods wouldn't be able to affect the original instance.
    Why when I update the treemap does the arraylist
    change, is this because the thing that is being put
    in the array list is infact not an object but simply
    a reference to an object?The ArrayList doesn't change at all. It's the instance that's being changed, and the ArrayList has a reference to it.

  • Functions to read and display an array of integers

    Hi guys,
    I am trying to implement with a class called Sort a function to read in an array of integers from a file and a function to display that array.
    public class Sort
         public static int[] read(String file) throws IOException
            /* Create Reader object to read contents of file */
            BufferedReader br = new BufferedReader(new FileReader(file));
            /* Read file and store lines in ArrayList */
            ArrayList<Integer> list = new ArrayList<Integer>();
            /* Variable */
            String in;
            /* While not equal to null reads data from file */
            while ((in = br.readLine()) != null)
                /* Adds data from file to ArrayList */
                list.add(Integer.parseInt(in));
            /* Converts ArrayList into an array */
            int[] array = new int[list.size()];
            for(int i = 0; i < list.size(); i++)
                /* Get array elements */
                array[i] = list.get(i);
            /* Returns array */
            return array;
        public int display()
            for (int i = 0; i < list.size(); i++)
                System.out.println(list.get(i));
    }I am having one of those moments when you forget everything, I need help with display the array in a seperate function, will someone help me please?
    Thanks!

    I know that its just implementing it.
    I have:
    public void display()
            for(int i = 0; i < array.length; i++)
                System.out.println(array);
    But I'm lost on how to make this work, i.e it says "cannot find array variable". I've not done Java for a while and feel like I have forgot everything!
    Edited by: mbruce10 on Nov 15, 2009 1:31 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • [resolved] Xorg 1.8, GeForce4 MX 4000, tv-out

    I have been happily watching videos from my computer to the TV via the svideo output. It looks like with Xorg 1.8 this is no longer possible as nvidia-96xx does not support the new xorg. Nouveau as far as I can figure out does not support tv-out for

  • Moving from Starter Edition 3.2 to Elements 6 on new Windows 7 computer

    I had been using Adobe Photoshop Album Starter Edition 3.2 on a Windows XP computer.  I recently got a new Windows 7 computer and I just used the Windows 7 Easy Transfer feature to move my images and other files from the Windows XP computer to my new

  • For non valuated sale order

    Hi Freinds, I got the following error while doing customization for Non-valuated sale order. In the Requirement class i selected the 40 and went in to details and have not selected any thing in the field Valuation which means i want to have "Non valu

  • When my ipod touch is on charge it does not work correct

    hello all i have noticed that when my new i pod touch 4th gen  is plugged in charging, when i try and use it its very difficult to do anything on it, just selecting a certain app seems to open a completely different on in a different location on the

  • SMTP Change

    Hello I would like to add at background en email to all our vendor using a function module. witch function should i use in order to do the same application as XK02? Thanks in advance, Emmanuel