Object in array list

Is it possible that object can be store in array list.
package{
// Importing object from flash libary
    import flash.text.TextField;
    import flash.display.Sprite;
// Creating class
     public class Show extends Sprite {
     //Attribute
    private var txt:Array = new Array();
     // Constructor 
       function Show()
               txt[0]:TextField =  new TextField();
                 addChild(txt[0]);
                 txt[0].width=320;
                 txt[0].height=25;
                 txt[0].x=0;
                 txt[0].y=0;
                 txt[0].border=true;
               txt[0].text="nepalikto";
Error
Description : Label must be a simple identifier
Location : Above orange textcolor line

Not sure if this all is 100% technically correct but:
You only use datatyping if you actually create a variable. Like:
var myArray:Array = new Array();
if you do not declare the var with the var keyword, you can't use datatyping either.
// this is wrong
myArray:Array = new Array()
It is good practice to use datatyping whenever possible since it can help you debug an application:
Flash finds the possible errors in code where one variable contains different datatypes at different times which can be confusing
Flash helps with the codecompletion feature once a variable is typed so there's less chance of typos.
The items in the array, unlike CS4's new Vector datatype aren't typed. Probably has some memory usage reason in the onderlying C++ code but I'm not sure. If you have CS4 you could possibly use:
var txt:Vector.<TextField> = new Vector.<TextField>();
To tell you the truth I haven't used the CS4 Vector Datatype so I'm not sure if aside from faster code execution there's errorcheckings on it's contents like mentioned above.
Hope this helps some

Similar Messages

  • Print object from Array list

    Program
    import java.util.*;
    public class ArrayQuestion {
         public static void main(String args[]) {
              int inputQuestionnAireNum = 0;
              int inputPostCode = 0;
              int inputGender = 0;
              int inputAge = 0;
              int x=0;
                 ArrayList<QuestionnAire> questionArr = new ArrayList<QuestionnAire> ();
                 Scanner input = new Scanner(System.in);
                 do{
                        System.out.print("1 new entry or 0 print");
                        x = Integer.parseInt(input.nextLine());  
                   if(x == 1){
                 //Questionnaire Number
                   System.out.print("Enter Questionnaire Number [ ] ");
                   inputQuestionnAireNum = Integer.parseInt(input.nextLine());
                   //Postal code
                   System.out.print("Enter Postal Code [ ] ");     
                   inputPostCode = Integer.parseInt(input.nextLine());
                   //Age
                   System.out.print("Enter Age [ ] ");
                   inputAge = Integer.parseInt(input.nextLine());
                   //Gender
                   System.out.print("Enter Gender '1' for Male and '2' for for female [ ] ");
                   inputGender = Integer.parseInt(input.nextLine());
                   QuestionnAire qObject = new QuestionnAire(inputQuestionnAireNum, inputPostCode, inputAge, inputGender);
                    questionArr.add(qObject);
                        } else {
                                for (int i = 0; i < questionArr.size(); i++) {
                                      System.out.println(questionArr.get(i));
                      } while(x != 0);
               output
    1 new entry or 0 print1
    Enter Questionnaire Number [ ] 222
    Enter Postal Code [ ] 111
    Enter Age [ ] 12
    Enter Gender '1' for Male and '2' for for female [ ] 1
    1 new entry or 0 print0
    QuestionnAire@4693c7how come the result is QuestionnAire@4693c7 instead of printing the value which i key in ???

    http://java.sun.com/javase/6/docs/api/java/lang/Object.html#toString()

  • Array of references to references to objects? Skip lists...

    I'm trying to hammer out a SkipList ADT by tomorrow night. The structure of my SkipList is basically: A Skip list has a reference to the first SkipListNode. Each SkipListNode has an array of links, where a link of level 1 links to the next node that is at least level 1 (every node is at least level 1), and array of 2 links to the next node down the list that is at least that tall, etc. For the last tallest node in the list, it will have links that are null, as there are no nodes after it which can reach up to its higher level links.
    My problem is that as I traverse the list looking for the insert position, I need to keep track of the taller links which may be 'cut-off' by the newly inserted node. Just as with a normal LinkedList, I would want to make the new node point to where these old links pointed, and point the old links to the new node. What I have been trying to do is build an array:
    SkipListNode previousLinks[] = new SkipListNode[levelOfTallestNodeInSkipList];
    As I traverse a SkipListNode, I over-write the previousLinks[i] with every level i link I encounter. For example say I'm in a level 5 node (currentNode) with key 15. I'm trying to inser key 17. I try the level 5 node's level 5 link and its null, so I would want to make previousLinks[5] = currentNode[5]. I then try currentNode's level 4 link, it's not null but it points to a node with key 47, which is past the insertion point for a node with key 17. So again, I want previousLinks[4] to REFER TO currentNode[4]. Etc, etc... I get down to currentNode's level 1 link and see it links to a node with key 16 and level 1. Ok, this is less than 17 so I make currentNode = key 16 node (which is lvl 1). Then I traverse currentNode's only link- a level 1 link- and see that it links to a node with key 18. BOOM: here's the insert point. I randomly select level 4 for the new node which will hold 17. This means that I will 'cut-off' the level four link of the node holding key 15. What I want to be able to do is:
    /*connect new links to where old links point to*/
    for (int k = 0; k < newNode.level; k++) {
    if (k < current.level)
    newNode.links[k] = previousLinks[k];
    else
    newNode.links[k] = null;
    /*connect old links to newly created node*/
    for (int k = 0;
    k < Math.min(current.level, newNode.level); k++)
    previousLinks[k] = newNode;
    But this doesn't work. The previousLinks array seems to only hold the values which were copied from the earlier nodes, not references to the fields in the nodes which point further down the list. What I want is a C++ style array of pointers to fields in an object's array so that I can change where these fields point (refer).
    I hope this post makes enough sense for someone to at least give me a clue... thanks.

    My skiplist implementation has a method to lookup a node. The resultant array of nodes has length the maximum height of the skiplist. At each level the array containes a reference to the node prior to the one I am looking for at that level. This allows me to patch all the relevant nodes when I add/remove an item to/from the skiplist.
    My code might help give you the idea.
         * Looks up the payload in the list returning an array
         * of nodes that point to the element immediately before
         * the desired element.
         * @param target the node we are searching for
         * @return and array of Nodes that are just prior to the
         * node we are looking for.
        private Node[] lookup(Node target)
            Node[] update = new Node[MAX_HEIGHT+1];
            int k = m_height;
            Node p = m_header;
            do
                Node q = null;
                while (((q = p.getNext(k) )!= null) && (m_comparator.lessThan(q, target))) p = q;
                update[k] = p;
            }  while (--k >= 0);
            return update;
        }

  • How can i check to see if an object is already in the array list?

    while (res.next()) {
                    Schedule schedule = new Schedule();
                    customerName = res.getString("CUSTOMERNAME");
                    schedule.setCustomerName(customerName);
                    magName = res.getString("MAGNAME");
                    schedule.setMagName(magName);
                    System.out.println("NAME: " + customerName);
                    System.out.println("MAGNAME: " + magName);
                    if(!scheduleListH.contains(schedule))  //this won't work
                        scheduleListH.add(schedule);
                }schedule object has 2 fields, customerName and MagName;
    Basically i want to say, IF the scheudleList (which is an array list) contains an object schedule that has the same customerName and MagName as any of the objects in the array list, don't readd the object.
    ANy help would be great!

    Thanks!
    Oops I forogt I could use the .contains, i also tried that but still no luck.
    There is no compiler error but here is an example of the output:
    Populating scheudle list for HOLIDAY selection data structure: 
    NAME: Cory
    MAGNAME: Merlin
    NAME: Brandon
    MAGNAME: Gondorf
    NAME: Chris
    MAGNAME: Houdini
    NAME: Lokie
    MAGNAME: Blaine
    Sample SCHEDUEL H [Cory          Merlin, Brandon          Gondorf, Chris          Houdini, Lokie          Blaine]As you can see, There are 4 objects in the array list:
    Cory Merlin
    Brandon Gondorf
    Chris Houdini
    Lokie BLaine
    Now this function is called everytime the user choses a new item in a combo box.
    So if they go back to the previous selection, Holiday's, it shouldn't read add all the orginal things.
    But if I go up and select the same item in the combo box it changes whats in the array list to the following:
    Populating scheudle list for HOLIDAY selection data structure: 
    NAME: Cory
    MAGNAME: Merlin
    NAME: Brandon
    MAGNAME: Gondorf
    NAME: Chris
    MAGNAME: Houdini
    NAME: Lokie
    MAGNAME: Blaine
    Sample SCHEDUEL H [Cory          Merlin, Brandon          Gondorf, Chris          Houdini, Lokie          Blaine, Cory          Merlin, Brandon          Gondorf, Chris          Houdini, Lokie          Blaine]Here's my whole function if your interested and where I call it:
        void populateSchedule(String holiday) {
            Statement sta = null;
            Connection connection6 = null;
            try {
                connection6 = DriverManager.getConnection(URL, USERNAME, PASSWORD);
                sta = connection6.createStatement();
                //getting the list of magicians from the selected holiday to see if any are free
                ResultSet res = sta.executeQuery(
                        "SELECT CUSTOMERNAME, MAGNAME FROM SCHEDULE WHERE HOLIDAYNAME = '" + holiday + "'");
                String customerName = " ";
                String magName = " ";
                System.out.println("Populating scheudle list for HOLIDAY selection data structure:  ");
                //this is where I add the waiting list objects to the array that will later be used
                //to print out and shown to the user when they select the waiting list status
                while (res.next()) {
                    Schedule schedule = new Schedule();
                    customerName = res.getString("CUSTOMERNAME");
                    schedule.setCustomerName(customerName);
                    magName = res.getString("MAGNAME");
                    schedule.setMagName(magName);
                    System.out.println("NAME: " + customerName);
                    System.out.println("MAGNAME: " + magName);
                   if(!scheduleListH.contains(schedule))
                       scheduleListH.add(schedule);
                System.out.println("Sample SCHEDUEL H " +   scheduleListH);
            } catch (SQLException ex) {
                System.out.println(ex);
                ex.printStackTrace();
            } finally {
                try {
                    sta.close();
                    connection6.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    //this is where i call in the GUI
        private void specStatusComboBoxActionPerformed(java.awt.event.ActionEvent evt) {                                                  
            // TODO add your handling code here:
            String selectedItem = (String)specStatusComboBox.getSelectedItem();
            String groupSelectedItem = (String) groupStatusComboBox.getSelectedItem();
            if(groupSelectedItem.equals("Holidays"))
                //get customer name and magician name from the Scheduel table
                //use selectedItem (it will be a holiday name)
                //magicDB.clearScheduleHList();
                magicDB.populateSchedule(selectedItem);
                ArrayList<Schedule> tempScheduleList = magicDB.getScheduleHListCopy();
                outputTextArea.setText(" ");
                outputTextArea.setText("CUSTOMER NAME" +"\t\t" + "MAGICIAN NAME" + "\n");
                for(int i = 0; i < tempScheduleList.size(); i++)
                    outputTextArea.append(tempScheduleList.get(i).toString() + "\n");
        }   I'll reward the duke stars anyways because you have been a great help either way!

  • When can we expect a patch for Object Array List Data Provider?

    Hey JSC Team!
    When can we expect maybe, just maybe a minor patch for the Object Array List Data Provider loading class problem? Next Month? This Year? Next Year? Near Future? Long in the future? Sometime in the 22nd century?

    I think one of the problem is
    when u declare the ObjectListDataProvider in ur backing bean
    it doesnt appear in the design time straight away
    u have to clean build close and re open the project
    which is quite time consuming.

  • How to bind bar chart(columns) to array list object in c# win form

    how to bind bar chart(columns) to array list  object in c#win form

    Hi Ramesh,
    Did you want to bind list object to bar chart? I made a simple code to achieve binding list to bar chart.
    public partial class Form0210 : Form
    public Form0210()
    InitializeComponent();
    private void Form0210_Load(object sender, EventArgs e)
    BindData();
    public void BindData()
    List<int> yValues = new List<int>(new int[] { 20, 30, 10, 90, 50 });
    List<string> xValues = new List<string>(new string[] { "1:00", "2:00", "3:00", "4:00", "5:00" });
    chart1.Series[0].Points.DataBindXY(xValues, yValues);
    The links below might be useful to you:
    # Data Binding Microsoft Chart Control
    http://blogs.msdn.com/b/alexgor/archive/2009/02/21/data-binding-ms-chart-control.aspx
    # Series and Data Points (Chart Controls)
    https://msdn.microsoft.com/en-us/library/vstudio/dd456769(v=vs.100).aspx
    In addition, if I misunderstood you, please share us more information about your issue.
    Best Regards,
    Edward
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

  • Please help with geometric objects in ARRAY...........

    I am facing a programming issue here;
    I am supposed to create an array of circle objects of random dimensions.
    Next, I am supposed to check each circle and make sure it does not intersect with any other circle in the array. If it does, I am expected to remove the circles that intersect with it from the array. I have found this technique more feasible, but in the question, it is suggested to check for intersection before the circle is added to the array. To quote "Check that the new circle does not intersect a previous one. You will need to iterate through the array list and verify that the current circle does not intersect with a circle in the array list. Add the circle to the array list if it does not intersect with another one." For some reason, I think my approach is more feasible. But feel free to differ.
    Then, I am supposed to draw the circles.
    The program compiles but when it is run, only one circle is drawn.
    Any advice would be appreciated, and as before thank you in advance.
    import java.util.Random;
    import java.awt.geom.Ellipse2D;
    import javax.swing.JComponent;
    import java.util.ArrayList;
    import java.awt.Graphics2D;
    import java.awt.Graphics;
    public class CirclesComponent extends JComponent
    public CirclesComponent(int numberCircles)
          NCIRCLES = numberCircles;
          circles = new ArrayList<Ellipse2D.Double>();
          final int XRANGE = 292;
          final int YRANGE = 392;
          final int RRANGE = 20;
             generator = new Random();
             double x = generator.nextInt(XRANGE) + 1;
             double y = generator.nextInt(YRANGE) + 1;
             double r = generator.nextInt(RRANGE) + 1;
             double w = 2 * r;
             double h = 2 * r;
             for (int i = 1; i <= NCIRCLES; i++)
             Ellipse2D anEllipse = new Ellipse2D.Double(x, y, w, h);
             circles.add(anEllipse);
          Test if two circles intersect.
          (distance between centers is less than sum of radii)
    public void circlesIntersect()
              Ellipse2D zeroEllipse = (Ellipse2D)circles.get(0);
               for (int v = 1; v <= circles.size(); v++)
                   Ellipse2D anotherEllipse = (Ellipse2D)circles.get(v);
                         double radius1 = zeroEllipse.getWidth() / 2;
                         double radius2 = anotherEllipse.getWidth() / 2;
                         double dx = zeroEllipse.getX() + radius1 - anotherEllipse.getX() - radius2;
                         double dy = zeroEllipse.getY() + radius1 - anotherEllipse.getY() - radius2;
                         double distance = Math.sqrt(dx * dx + dy * dy);
                         if (distance < radius1 + radius2)
                         circles.remove(v);
       public void paintComponent(Graphics g)
          Graphics2D g2 = (Graphics2D) g;
          for (int z = 0; z < circles.size(); z++) // iterate through every circle in the list
          g2.draw((Ellipse2D)circles.get(z)); // draw the circle
       public void getRejection()
           System.out.println("The percentage of rejected circles is " + ((circles.size() / NCIRCLES ) * 100));
           System.out.println("The size of the array is " + (circles.size()));
       private int NCIRCLES; 
       private ArrayList circles;
       private Random generator;
    import java.util.Scanner;
    import java.awt.Graphics2D;
    import java.awt.Graphics;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    public class CirclesTester
    public static void main(String[] args)
          Scanner thescanner = new Scanner(System.in);
          System.out.print("How many circles do you want? ");
          int totalCircles = thescanner.nextInt();
          CirclesComponent theCircle = new CirclesComponent(totalCircles);
          theCircle.getRejection();
          JFrame frame = new JFrame();
          frame.setSize(300, 400);
          frame.setTitle("Non-Intersecting Circles");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(theCircle);
          frame.setVisible(true);
    }

    homebrewed wrote:
    I am supposed to create an array of circle objects of random dimensions.
    Next, I am supposed to check each circle and make sure it does not intersect with any other circle in the array. If it does, I am expected to remove the circles that intersect with it from the array. I have found this technique more feasible, but in the question, it is suggested to check for intersection before the circle is added to the array. To quote "Check that the new circle does not intersect a previous one. You will need to iterate through the array list and verify that the current circle does not intersect with a circle in the array list. Add the circle to the array list if it does not intersect with another one." For some reason, I think my approach is more feasible. But feel free to differ.Gladly. It is much simpler to iterate over a List and check if the new circle is valid than to iterate over a List and remove those circles that make the new circle invalid. Note that the code you have now will skip items in the list when a circle is removed.
    Then, I am supposed to draw the circles.
    The program compiles but when it is run, only one circle is drawn. And why is that? Is it only drawing one of the circles? Is it drawing all the circles but they're all the same circle? Does your list only contain one circle?
    You need to run your program in a debugger or add println() statements to output your program state at important points along the execution path.
    Once you figure out why you're only getting one circle, it becomes much simpler to figure out how it happened.

  • Is possible to pass array/list as parameter in TopLink StoredProcedureCall?

    Hi, We need to pass an array/List/Vector of values (each value is a 10 character string) into TopLink's StoredProcedureCall. The maximum number of elements on the list is 3,000 (3,000 * 10 = 30,000 characters).
    This exposed two questions:
    1. Is it possible to pass a Vector as a parameter in TopLink's StoredProcedureCall, such as
    StoredProcedureCall call = new StoredProcedureCall();
    call.setProcedureName("STORED_PROCEDURE_NAME");
    call.addNamedArgument("PERSON_CODE");
    Vector strVect = new Vector(3000);
    strVect.add(“ab-gthhjko”);
    strVect.add(“cd-gthhjko”);
    strVect.add(“ef-gthhjko”);
    Vector parameters = new Vector();
    parameters.addElement(strVect);
    session.executeQuery(query,parameters);
    2. If the answer on previous question is yes:
    - How this parameter has to be defined in Oracle’s Stored Procedure?
    - What is the maximum number of elements/bytes that can be passed into the vector?
    The best way that we have found so far was to use single string as a parameter. The individual values would be delimited by comma, such as "ab-gthhjko,cd-gthhjko,ef-gthhjko..."
    However, in this case concern is the size that can be 3,000 * 11 = 33, 000 characters. The maximum size of VARCHAR2 is 4000, so we would need to break calls in chunks (max 9 chunks).
    Is there any other/more optimal way to do this?
    Thanks for your help!
    Zoran

    Hello,
    No, you cannot currently pass a vector of objects as a parameter to a stored procedure. JDBC will not take a vector as an argument unless you want it to serialize it (ie a blob) .
    The Oracle database though does have support for struct types and varray types. So you could define a stored procedure to take a VARRAY of strings/varchar, and use that stored procedure through TopLink. For instance:
    StoredProcedureCall call = new StoredProcedureCall();
    call.setProcedureName("STORED_PROCEDURE_NAME");
    call.addNamedArgument("PERSON_CODE");
    oracle.sql.ArrayDescriptor descriptor = new oracle.sql.ArrayDescriptor("ARRAYTYPE_NAME", dbconnection);
    oracle.sql.ARRAY dbarray = new oracle.sql.ARRAY(descriptor, dbconnection, dataArray);
    Vector parameters = new Vector();
    parameters.addElement(dbarray);
    session.executeQuery(query,parameters);This will work for any values as long as you are not going to pass in null as a value as the driver can determine the type from the object.
    dataArray is an Object array consisting of your String objects.
    For output or inoutput parameters you need to set the type and typename as well:
      sqlcall.addUnamedInOutputArgument("PERSON_CODE", "PERSON_CODE", Types.ARRAY, "ARRAYTYPE_NAME"); which will take a VARRAY and return a VARRAY type object.
    The next major release of TopLink will support taking in a vector of strings and performing the conversion to a VARRAY for you, as well as returning a vector instead of a VARRAY for out arguments.
    Check out thread
    Using VARRAYs as parameters to a Stored Procedure
    showing an example on how to get the conection to create the varray, as well as
    http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/varray/index.html on using Varrays in Oracle, though I'm sure the database docs might have more information.
    Best Regards,
    Chris

  • Adding two array lists together and a text file to an array list

    I'm having problems coding these two methods... Could someone explain how to do this? I can't find information on it anywhere... :(
    "MagazineList" is the class I'm coding in right now, and I already declared "list" as an array list of another class called "Magazine".
    public boolean addAll(MagazineList magazines)
           if (list == magazines) {
               return false;
            else {
                list.addAll(magazines);
           return true;
       public boolean addAll(String filename)
           Scanner in = ResourceUtil.openFileScanner(filename);
            if (in == null) {
               return false;
            String line = source.nextLine();
            while (!line.equals("")) {
              list.add(Magazine(source));
           in.close();
       }

    I assume "addAll(MagazineList magazines)" is defined in the MagazineList class?
    Then,
    list.addAll(magazines);probably needs to be something like:
    list.addAll(magazines.list);This uses the private variable ( should be private) list from the input MagazineList, and adds all of those Magazine objects to the list in the current MagazineList.
    But, yes, describe your problems more clearly, and you'll get better answers more quickly (because people will be able to understand you and give you a suggestion without asking you another question first).

  • How to get keep one column as a key and the other columns as a array list

    Hello,
    I am really new to Java...I am trying to read a text file containing different columns separated by comma and then create a hash map for the first column (key) and then rest as a array list for the key.I am not able to create the hash map and the corresponding key.Could someone help me in this regard.
    The text document is :
    AcctNo,AcctMngr,AcctType,ProdList,Volume,AcctPrice,Returns
    12345,Vikram,2,MSFS:IBM:XYZ:MAN,28000,4500,1.25
    53278,Anand,1,PLYS:AIX:YET:WON,85000,8500,2.32
    94005,Vincent,3,UTIL:FLY:YEL:WIN,67000,5600,3.21
    45000,Abhishek,2,WENS:KYL:MEN:ABS,34000,9800,4.21
    76000,Chris,3,MENS:IBM:ROC:QUE,25000,2500,2.15
    67000,Kiran,4,FORS:ITI:MOC:REM,32000,3500,1.54
    87000,Rohit,2,MSNF:IIT:HOT:ROC,54000,5400,4,23
    45600,Sathyan,3,HELP:FOR:PRO:GRA,65000,3400,2,1.98
    84600,Vinay,4,PLZE:TES:ROC:WEN,76000,7300,3,4.32
    65000,Venkat,2,HETT:WEL:SEE:RED,89000,9800,1,3.23
    and the code which i have so far is
    import java.io.*;
    import java.util.*;
    class SearchHash {
    public static void main (String args[]) {
    int i=0;
    int j=0;
    Object newKey = new Object();
    Object newValue = new Object();
    Map map1 = new HashMap();
    ArrayList a1 = new ArrayList();
    String val;
    try {
    BufferedReader br1 = new BufferedReader ( new FileReader ( new File ("progress.txt")));
    String s="";
    s = br1.readLine();
    while (s!=null) {
    StringTokenizer st = new StringTokenizer (s ,",");
    int k=0;
    while (st.hasMoreTokens()) {
    while (k<=6) {
    val= st.nextToken();
    if (k==0) {
    newKey = val;
    else{
    newValue = val;
    a1.add(newValue);
    k = k+ 1;
    map1.put(newKey,a1);
    map1.put(newKey,a1);
    a1.clear();
    s = br1.readLine();
    // System.out.println(map1);
    }catch (Exception e) {
    System.out.println("Exception Raised : " + e);
    Thanks.,...

    Array? Don't live in object denial. Define a class (Account?) and parse each line as an Account object. Then you put them into a Map<Integer, Account> by their account number.

  • Bank account array list

    I'm very lost and need a push in the right direction. I am trying to get the balance of a bank account which is an array list of accounts and balances. The class I am working on is the Bank class. There is also a BankAccount class and a BankTester class.
    //deposit funds
         public void deposit(int accountNumber, double amount)
              double bal = (accountNumber).getBalance();
              double newBalance = bal + amount;
              balance = newBalance;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    This is the error I am getting that I do not understand.
    C:\Users\matthew\Documents\FLCC\CSC190\Exercise7_1\Bank.java:34: int cannot be dereferenced
              double bal = (accountNumber).getBalance();
              ^
    C:\Users\matthew\Documents\FLCC\CSC190\Exercise7_1\Bank.java:36: cannot find symbol
    symbol : variable balance
    location: class Bank
              balance = newBalance;
              ^

    mgp wrote:
    I'm very lost and need a push in the right direction. I am trying to get the balance of a bank account which is an array list of accounts and balances. The class I am working on is the Bank class. There is also a BankAccount class and a BankTester class.
    //deposit funds
         public void deposit(int accountNumber, double amount)
              double bal = (accountNumber).getBalance();
              double newBalance = bal + amount;
              balance = newBalance;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    This is the error I am getting that I do not understand.
    C:\Users\matthew\Documents\FLCC\CSC190\Exercise7_1\Bank.java:34: int cannot be dereferenced
              double bal = (accountNumber).getBalance();
    OK, here is what I think is happening. I do not see a definition of accountNumber anyplace that would override the int definition in the parameter list, and you are trying to access it as a object with a method getBalance()--that is what the dereference error is saying--when you put the parentesis around the variable and then attaching a method to it you are trying to access the enclosed variable as an object. In any case it is not an object and it does not contain the method getBalance().
              ^
    C:\Users\matthew\Documents\FLCC\CSC190\Exercise7_1\Bank.java:36: cannot find symbol
    symbol : variable balance
    location: class Bank
              balance = newBalance;
              ^balance is undefined in your Bank class.

  • Previous element in array list

    hello ppl..
    i hope u guys can help me here.. i am developing a program that sort an amount of strings and output to a file..and i place them inside an array list..i use Collections.sort to sort it..
    now the problem is..i want to handle duplicate strings meaning deleting the duplicate strings..however my code doesnt seem to work..here it is
    Iterator check = c.iterator();
    while (check.hasNext() == true)
    if (check.previous() == check.next())
    check.remove();
    br.write(check.next() + "\r\n");
    c is my arraylist name. JDK's error is they cannot resolve symbol previous () method but i found it inside util and i imported the whole util..by import java.util.*;
    Please help..thank you

    Good catch. It's very rare that you use == to compare objects. You only do that when you want to see if the two references are both aimed at the same object. Normally what you want to do (and what should be done here) is to use equals to see if the two objects' "contents" or "values" are the same.
    >
    if (check.previous() == check.next())Did you use this piece in the program?
    If so could this be the problem?
    I think that when you use the "==" operator it checks
    to see if the two objects share the same memory
    location.
    Like when you are comparing Strings you must use the
    String.equals(String s) method they they will never
    match with "==".
    Maybe this is not the problem but I like to
    ramble...
    -- Ian

  • How to find and display the posistion in an array list

    hi all,
    i know this is proballly simple but i have an arraylist where every time someone connects to my system it adds them to an arraylist, how can i post back somelike like hi user "1" thanks for connecting and so on. i just dont understand how to find their unique posistion in the array list and display it as a number.
    any help would be great

    So to be clear...
    You have an arraylist of connections .... for example
    ArrayList<ConnectedPeople> connPplArr = new ArrayList();And then each time someone connects you would add a connected people object to the arraylist.
    ConnectedPeople, migh contain username etc etc.
    You could then do:
    ConnectedPeople newConnection..... ;
    int index = connPplArr.indexOf( newConnection );
    if(int == -1){
        add them to your array
        index = connPplArr.size();
    return "Hello user "+ index;That what you mean?
    I know some of it is sudo code, but have I understood your problem?
    Edited by: Azzer_Mac on Apr 29, 2008 2:20 AM
    Edited by: Azzer_Mac on Apr 29, 2008 2:20 AM

  • A suggestion : use "loop array list" instead of ArrayList / LinkedList

    ArrayList is good at:
    get / set by index : O(1)
    appending : O(log(n))
    remove last : O(1)
    and very bad at:
    add middle : O(n)
    remove from middle : O(n)
    LinkedList is good at:
    fast remove from middle, if your iteraror already goes there : O(1)
    convenient methods : addFirst, addLast, removeFirst, removeLast : O(1)
    and very bad at :
    get / set by index : O(n)
    here I want to make a suggestion : use "loop array list" instead of the ArrayList and LinkedList.
    a "loop array list" is based on array, just like ArrayList. But it has 2 member-variables : the start position, and the real size. the start position can be anywhere within array.length. an element of index "i" is stored in array[ start + i ], and when (start + i > array.length), loop to the beginning of the array; when (start + i < 0), loop to the end of the array.
    this "loop array list" has all the good sides:
    get / set by index : O(1)
    add first / last : O(log(n))
    remove first / last : O(log(n))
    add / remove from middle : O(n)
    (note : because we shrink the backup-array when the real size is too small, add / remove operation take O(log(n)) now.)
    the only problem is : add / remove from middle. let's take a look at it.
    1. the LinkedList does NOT really add/remove from middle in O(1), you has to locate the element, which is O(n).
    2. O(n) is acceptable, O(n^2) is not acceptable. try this : keep removing first element from an very big ArrayList ( size>10^6 ) until it's empty.
    the fact is, any list can perform batch-remove / batch-add operation in O(n) instead of O(n^2). it's easy : allocate a new list, iterate the original list, copy the element into the new list if condition is satisfied.
    so, instead of "remove from middle", what we need is a new methods : removeAllByCondition( Condition condition ), and now the batch-remove operation can be done in O(n)
    here is an implementation of mine. I've tested it on my computer( 512mem + 2G cpu, win2k + jdk1.5 ), it's amazing, just a little slower then ArrayList when add last, and a liitle slower then LinkedList when batch-remove. in all other cases, it's far more better then those 2 kinds of List.
    // source code : List2
    import java.util.AbstractList;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collection;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.List;
    import java.util.NoSuchElementException;
    import java.util.Set;
    public final class List2<T> extends AbstractList<T> {
    private static int initialArrayLength = 4;
    private T[] array;
    private int start;
    private int size;
    private void init( T[] newArray, int start_a, int size_a ) {
    array = newArray;
    start = start_a;
    size = size_a;
    @SuppressWarnings("unchecked")
    private void init() {
    init( (T[]) new Object[ initialArrayLength ], 0, 0 );
    public List2() {
         init();
    @SuppressWarnings("unchecked")
    public List2( Collection<? extends T> collection ) {
         init(
              collection.toArray( (T[]) new Object[ collection.size() * 11 / 10 + 1 ] ),
              0,
              collection.size()
    private List2( T[] array_a, int start_a, int size_a ) {
         init( array_a, start_a, size_a );
    @SuppressWarnings("unchecked")
    public static <TT> List2<TT> createV( TT... elements ) {
         TT[] array = (TT[]) new Object[ elements.length * 11 / 10 + 1 ];
         System.arraycopy( elements, 0, array, 0, elements.length );
         return new List2<TT>( array, 0, elements.length );
    public static List2<Double> create( double... elements ) {
         Double[] array = new Double[ elements.length * 11 / 10 + 1 ];
         for( int i=0; i < elements.length; i++ )
              array[i] = elements;
         return new List2<Double>( array, 0, elements.length );
    public static List2<Integer> create( int... elements ) {
         Integer[] array2 = new Integer[ elements.length * 11 / 10 + 1 ];
         for( int i=0; i < elements.length; i++ )
              array2[i] = elements[i];
         return new List2<Integer>( array2, 0, elements.length );
    public static List2<Character> create( char... elements ) {
         Character[] array2 = new Character[ elements.length * 11 / 10 + 1 ];
         for( int i=0; i < elements.length; i++ )
              array2[i] = elements[i];
         return new List2<Character>( array2, 0, elements.length );
    public static List2<Character> create( String s ) {
         return create( s.toCharArray() );
    public List2<T> clone() {
         return new List2<T>( this );
    // basic
    public int size() {
         return size;
    private int index( int index ) {
         int i = start + index;
         if( i >= array.length )
              i -= array.length;
         return i;
    public T get( int d ) {
         if( d < 0 || d >= size )
              throw new IndexOutOfBoundsException();
         if( size == 0 )
              throw new NoSuchElementException();
         return array[ index( d ) ];
    public T set( int index, T element ) {
         if( index < 0 || index >= size )
              throw new IndexOutOfBoundsException();
         int i = index( index );
         T oldElement = array[i];
         array[i] = element;
         return oldElement;
    @SuppressWarnings("unchecked")
    private void copyAndSetToNewArray( int newArrayLength ) {
         T[] newArray = (T[]) new Object[ newArrayLength ];
         for( int i=0; i<size; i++ )
              newArray[i] = array[ index( i ) ];
         init( newArray, 0, size );
    public void addFirst( T element ) {
         if( size == array.length )
              copyAndSetToNewArray( size * 3 / 2 + 1 );
         int i = index( array.length - 1 );
         array[ i ] = element;
         start = i;
         size++;
    public void addLast( T element ) {
         if( size == array.length )
              copyAndSetToNewArray( size * 3 / 2 + 1 );
         array[ index( size ) ] = element;
         size++;
    public T removeFirst() {
         if( size == 0 )
              throw new NoSuchElementException();
         T oldElement = array[ start ];
         array[ start ] = null;
         start = index( 1 );
         size--;
         if( array.length > size * 2 + 1 )
              copyAndSetToNewArray( size * 11 / 10 + 1 );
         return oldElement;
    public T removeLast() {
         if( size == 0 )
              throw new NoSuchElementException();
         int i = index( size - 1 );
         T oldElement = array[i];
         array[i] = null;
         size--;
         if( array.length > size * 2 + 1 )
              copyAndSetToNewArray( size * 11 / 10 + 1 );
         return oldElement;
    @SuppressWarnings("unchecked")
    public int removeAll( ListCondition<T> condition ) {
         T[] newArray = (T[]) new Object[ array.length ];
         int iNew = 0;
         for( int i=0; i < size; i++ ) {
              T element = get( i );
              if( ! condition.isConditionSatisfied( this, i, element ) )
                   newArray[ iNew++ ] = element;
         int oldSize = size;
         init( newArray, 0, iNew );
         if( array.length > size * 2 + 1 )
              copyAndSetToNewArray( size * 11 / 10 + 1 );
         return size - oldSize;
    // aux
    public boolean equals(Object obj) {
         if( obj == this )
         return true;
         if( obj instanceof List2 ) {
              List2 that = (List2) obj;
              if( this.size != that.size )
                   return false;
              for( int i=0; i < size; i++ )
                   if( ! Tools.equals( this.array[ this.index(i) ], that.array[ that.index(i) ] ) )
                        return false;
              return true;
         if( obj instanceof List ) {
              List that = (List) obj;
              if( this.size != that.size() )
                   return false;
              Iterator thatIter = that.iterator();
              for( int i=0; i < size; i++ )
                   if( ! Tools.equals( this.array[ this.index(i) ], thatIter.next() ) )
                        return false;
              return true;
         return true;
    public int hashCode() {
         int hashCode = 1;
         for( int i=0; i < size; i++ ) {
              T element = array[ index( i ) ];
         hashCode = 31*hashCode + ( element==null ? 0 : element.hashCode() );
         return hashCode;
    public boolean isEmpty() {
         return size == 0;
    public T getFirst() {
         return get( 0 );
    public T getLast() {
         return get( size() - 1 );
    public T getRandom() {
         return get( (int) (Math.random() * size) );
    public int indexOf( Object element ) {
         for( int i=0; i < size; i++ )
              if( Tools.equals( array[ index( i ) ], element ) )
                   return i;
         return -1;
    public int lastIndexOf( Object element ) {
         for( int i=size-1; i >= 0; i-- )
              if( Tools.equals( array[ index( i ) ], element ) )
                   return i;
         return -1;
    public boolean contains( Object element ) {
         return indexOf( element ) != -1;
    public boolean add( T element ) {
         addLast( element );
         return true;
    @Deprecated
    public void add( int index, T element ) {
         throw new UnsupportedOperationException();
    public T remove() {
         return removeFirst();
    @Deprecated
    public boolean remove( Object element ) {
         throw new UnsupportedOperationException( "use removeAll( Condition ) instead" );
    @Deprecated
    public T remove( int index ) {
         throw new UnsupportedOperationException( "use removeAll( Condition ) instead" );
    public void clear() {
         init();
    public Object[] toArray() {
         Object[] result = new Object[ size ];
         for( int i=0; i < size; i++ )
         result[i] = array[ index( i ) ];
         return result;
    @SuppressWarnings("unchecked")
    public <TT> TT[] toArray( TT[] a ) {
    if( a.length < size )
    a = (TT[]) java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), size );
    for( int i=0; i < size; i++ )
    a[i] = (TT) array[ index( i ) ];
    if( a.length > size )
         a[size] = null;
    return a;
    @SuppressWarnings("unchecked")
    public void sort() {
         Object[] a = toArray();
         Arrays.sort( a );
         for( int i=0; i < size; i++ )
              array[ i ] = (T) a[ i ];
         start = 0;
    @SuppressWarnings("unchecked")
    public void sortDesc() {
         Object[] a = toArray();
         Arrays.sort( a );
         for( int i=0, j=size-1; i < size; i++, j-- )
              array[ i ] = (T) a[ j ];
         start = 0;
    @SuppressWarnings("unchecked")
    public void sort( Comparator<T> comparator ) {
         T[] a = (T[]) toArray();
         Arrays.sort( a, comparator );
         for( int i=0; i < size; i++ )
              array[ i ] = a[ i ];
         start = 0;
    @SuppressWarnings("unchecked")
    public void sortDesc( Comparator<T> comparator ) {
         T[] a = (T[]) toArray();
         Arrays.sort( a, comparator );
         for( int i=0, j=size-1; i < size; i++, j-- )
              array[ i ] = a[ j ];
         start = 0;
    public String toString( String delimiter ) {
         return toString( "", delimiter, "", size() );
    public String toString( String prefix, String delimiter, String suffix, int max ) {
         StringBuffer stringBuffer = new StringBuffer( prefix );
         int dest = Math.min( max, size );
         for( int i=0; i < dest; i++ ) {
              stringBuffer.append( get(i) );
              if( i < dest - 1 )
                   stringBuffer.append( delimiter );
         if( size > max )
              stringBuffer.append( "...(" ).append( size() - max ).append( " more)" );
         stringBuffer.append( suffix );
         return stringBuffer.toString();
    // batch operation
    public boolean containsAll( Collection<?> that ) {
         Set<Object> thisSet = new HashSet<Object>( this );
         for( Object element : that )
              if( ! thisSet.contains( element ) )
                   return false;
         return true;
    @SuppressWarnings("unchecked")
    public List2<T> subList( int fromIndex, int toIndex ) {
         if( fromIndex < 0 || toIndex > size || toIndex < fromIndex )
              throw new IndexOutOfBoundsException();
         int newSize = toIndex - fromIndex;
         T[] newArray = (T[]) new Object[ newSize * 11 / 10 + 1 ];
         for( int i=fromIndex, iNew=0; i < toIndex; i++, iNew++ )
              newArray[ iNew ] = array[ index( i ) ];
         return new List2<T>( newArray, 0, newSize );
    public void addV( T... that ) {
         for( T element : that )
              addLast( element );
    public boolean addAll( Collection<? extends T> that ) {
         for( T element : that )
              addLast( element );
         return ! that.isEmpty();
    @Deprecated
    public boolean addAll( int index, Collection<? extends T> c ) {
         throw new UnsupportedOperationException();
    public void removeRest( T element ) {
         int position = lastIndexOf( element );
         if( position == -1 )
              return;
         while( ! Tools.equals( element, removeLast() ) );
    public void removeAllEquals( final T element ) {
         removeAll( new ListCondition<T>() { public boolean isConditionSatisfied(List2 list, int index, T currentElement) {
              return currentElement.equals( element );
    public void removeAllBetween( final T from, final T to ) {
         removeAll( new ListCondition<T>() {
              @SuppressWarnings("unchecked")
              public boolean isConditionSatisfied(List2 list, int index, T element) {
                   if( from != null && ((Comparable) from).compareTo( element ) > 0 )
                        return false;
                   if( to != null && ((Comparable) to).compareTo( element ) <= 0 )
                        return false;
                   return true;
    public boolean retainAll( Collection<?> that ) {
         final Set<Object> thatSet = new HashSet<Object>( that );
         int removeCount = removeAll( new ListCondition<T>() { public boolean isConditionSatisfied(List2 list, int index, T element) {
              return ! thatSet.contains( element );
         return removeCount > 0;
    public boolean removeAll( Collection<?> that ) {
         final Set<Object> thatSet = new HashSet<Object>( that );
         int removeCount = removeAll( new ListCondition<T>() { public boolean isConditionSatisfied(List2 list, int index, T element) {
              return thatSet.contains( element );
         return removeCount > 0;
    // unit test
    private static int maxTestCount = 1000 * 1000;
    public static void unitTest() throws Exception {
         // thest thoese methods for one time
         Tools.ensureEquals( new List2(), new ArrayList() );
         Tools.ensureNotEquals( List2.create( "abcde" ), new ArrayList() );
         Tools.ensureNotEquals( List2.create( "abcde" ), List2.create( "abcdef" ) );
         final List<Double> list1 = new ArrayList<Double>();
         final List2<Double> list2 = new List2<Double>();
         Runnable[] tasks = new Runnable[] {
              // test those methods that do NOT change the list
              new Runnable() { public void run() {
                   Tools.ensureEquals( new List2<Double>( list1 ), list1 );
                   Tools.ensureEquals( List2.createV( list1.toArray() ), list1 );
                   Tools.ensureEquals( List2.createV( list1.toArray( new Double[0] ) ), list1 );
                   double[] doubles = new double[ list1.size() ];
                   int i = 0;
                   for( double d : list1 )
                        doubles[i++] = d;
                   Tools.ensureEquals( List2.create( doubles ), list1 );
                   Tools.ensure( list1.isEmpty() == list2.isEmpty() );
                   Arrays.equals( list1.toArray(), list2.toArray() );
                   Tools.ensureEquals( list1, list2.clone() );
                   Double notExistElement = -2.0;
                   Tools.ensure( list1.indexOf( notExistElement ) == -1 );
                   Tools.ensure( list1.lastIndexOf( notExistElement ) == -1 );
                   Tools.ensure( list1.contains( notExistElement ) == false );
                   Tools.ensureEquals( list1.toString(), list2.toString() );
                   Tools.ensureEquals( list1.toString(), list2.toString() );
                   Tools.ensureEquals( list1.hashCode(), list2.hashCode() );
                   if( list1.isEmpty() )
                        return;
                   Tools.ensure( list1.get(0).equals( list2.getFirst() ) );
                   Tools.ensure( list1.get(list1.size()-1).equals( list2.getLast() ) );
                   Double existRandomElement = list2.getRandom();
                   Tools.ensure( list1.contains( existRandomElement ) );
                   Tools.ensure( list2.contains( existRandomElement ) );
                   Tools.ensure( list1.indexOf( existRandomElement ) == list2.indexOf( existRandomElement ) );
                   Tools.ensure( list1.indexOf( existRandomElement ) == list2.indexOf( existRandomElement ) );
                   int from = (int) (Math.random() * list1.size());
                   int to = (int) (Math.random() * (list1.size()+1));
                   if( from > to ) {
                        int t = from;
                        from = to;
                        to = t;
                   Tools.ensureEquals( list1.subList( from, to ), list2.subList( from, to ) );
              // test those methods that change the list
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   int i = (int) (Math.random() * list1.size());
                   double d = Math.random();
                   list1.set( i, d );
                   list2.set( i, d );
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   int i = (int) (Math.random() * list1.size());
                   Tools.ensure( list1.get( i ).equals( list2.get( i ) ) );
              new Runnable() { public void run() {
                   double d = Math.random();
                   list1.add( 0, d );
                   list2.addFirst( d );
              new Runnable() { public void run() {
                   double d = Math.random();
                   list1.add( d );
                   list2.addLast( d );
              new Runnable() { public void run() {
                   double d = Math.random();
                   list1.add( d );
                   list2.addLast( d );
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   Tools.ensure( list1.remove( 0 ).equals( list2.removeFirst() ) );
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   Tools.ensure( list1.remove( list1.size() - 1 ).equals( list2.removeLast() ) );
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   int i = 0;
                   for( Iterator<Double> iter=list1.iterator(); iter.hasNext(); i++ ) {
                        iter.next();
                        if( i % 3 == 0 )
                             iter.remove();
                   list2.removeAll( new ListCondition<Double>() { public boolean isConditionSatisfied(List2 list, int index, Double element) {
                        return index % 3 == 0;
              new Runnable() { public void run() {
                   double d = Math.random();
                   list1.add( d );
                   list2.add( d );
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   Tools.ensure( list1.remove(0).equals( list2.remove() ) );
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   int r = (int) (Math.random() * list1.size());
                   Double element = list1.get( r );
                   int index = list1.lastIndexOf( element );
                   for( int i=list1.size()-1; i>=index; i-- )
                        list1.remove( i );
                   list2.removeRest( element );
              new Runnable() { public void run() {
                   list2.removeRest( Math.random() - 2 );
              new Runnable() { public void run() {
                   list1.clear();
                   list2.clear();
              new Runnable() { public void run() {
                   Collections.sort( list1 );
                   list2.sort();
              new Runnable() { public void run() {
                   Collections.sort( list1 );
                   Collections.reverse( list1 );
                   list2.sortDesc();
              new Runnable() { public void run() {
                   Comparator<Double> comparator = new Comparator<Double>() { public int compare(Double o1, Double o2) {
                        return o1.toString().substring(2).compareTo( o2.toString().substring(2) );
                   Collections.sort( list1, comparator );
                   list2.sort( comparator );
              new Runnable() { public void run() {
                   Comparator<Double> comparator = new Comparator<Double>() { public int compare(Double o1, Double o2) {
                        return o1.toString().substring(2).compareTo( o2.toString().substring(2) );
                   Collections.sort( list1, comparator );
                   Collections.reverse( list1 );
                   list2.sortDesc( comparator );
              new Runnable() { public void run() {
                   Double notExistElement = -2.0;
                   list2.removeAllEquals( notExistElement );
                   Tools.ensureEquals( list1, list2 );
                   list2.removeAllBetween( 0.5, 0.6 );
                   for( Iterator<Double> iter=list1.iterator(); iter.hasNext(); ) {
                        double d = iter.next();
                        if( d >= 0.5 && d < 0.6 )
                             iter.remove();
                   Tools.ensureEquals( list1, list2 );
         System.out.print( "test List2 " );
         for( int i=0; i < maxTestCount; i++ ) {
              tasks[ (int) (Math.random() * tasks.length) ].run();
              Tools.ensureEquals( list1, list2 );
              if( i % (maxTestCount/10) == 0 )
                   System.out.print( "." );
         System.out.println( " ok" );
    // source code : ListCondition
    public interface ListCondition<T> {
    boolean isConditionSatisfied( List2 list, int index, T element );

    Hi,
    I have the following statement:
    private List list = new ArrayList();
    why not use private ArrayList list = new
    ArrayList()?
    I know ArrayList implements List, so list has a wide
    scope, right? What's the benefit?
    Thanks,
    JieBy using the interface you are not tied to a specific implementation.
    Later, you may determine that using a LinkedList is more efficient to your specific code and then all you need to do is change the statement to:
    private List list = new LinkedList();As long as you are not casting the list reference to ArrayList (or something along those lines) you would not need to change anything else.

  • Add object in the list

    hi how are you guys ? i hope you all fine ..
    here ...
    iam trying to show the list items in the list .. but i couldn.t here
    first i created object and array object
    var za:int = 0
    var itemsinfo:Object = new Object()
    var da:Array = new Array (100)
    then in another place  i set the properties for the object , andi made them arrays objects like this
    itemsinfo.name1 = new Array()
       itemsinfo.price1 = new Array()
    after that i,ve crated 2 text boxes , one for the item value and the second for the price
    additemsvar = additems.text
       addpricevar = int (addprice.text)
    then i checked the values in the object
    for (var z:String in itemsinfo){
        trace (z + ":" + itemsinfo[z])
    and  every thing is good , but the probelm is when i add these arrays to to the list object, it doesn,t work
    i.ve tried with 3 deffrent ways
    listbox1.addItem ({label:String(itemsinfo.name1[za])}) //displaying undefined in the list
       listbox1.addItem ({label:(itemsinfo.name1[za])}) //displaying nothing and it just take a place
    listbox1.addItem (itemsinfo.name1[za])  // nothing happend
    thank you

    iam not realy sure if i can understand you , but how can i fix it
    listbox1.addItem (...)
    here is the full code
    package {
    import flash.display.MovieClip;
       import flash.events.MouseEvent
       import flash.events.Event;
    public class MAIN  extends MovieClip {
      var additemsvar:String
      var addpricevar:int
      var removeitemvar:int
      var itemsnp:Array = new Array (100)
      var itemsinfo:Object = new Object()
      var za:int = 0
      var da:Array = new Array (100)
      public function MAIN () {
        addbutton.addEventListener(MouseEvent.CLICK ,addbutton1)
        removebutton.addEventListener(MouseEvent.CLICK ,removebutton1)
        addEventListener(Event.ENTER_FRAME , onEnterFrame)
      addEventListener(Event.ADDED_TO_STAGE,ADDED_TO_STAGE)
      public function ADDED_TO_STAGE (event:Event){
       itemsinfo.name1 = new Array()
       itemsinfo.price1 = new Array()
      public function onEnterFrame (event:Event){
       if(listbox1.selectedIndex != -1){
       itemname11.text = String({label:listbox1.getItemAt(listbox1.selectedIndex)})
      public function addbutton1 (event:MouseEvent){
       additemsvar = additems.text
       addpricevar = int (addprice.text)
       listbox1.addItem ({label:String(itemsinfo.name1[za])})
       listbox2.addItem ({label:itemsnp[za]})
       itemsinfo.name1.push (additemsvar)
       itemsinfo.price1.push (addpricevar)
       za += 1
       trace (itemsinfo.name1)
       for (var z:String in itemsinfo){
        trace (z + ":" + itemsinfo[z])
      public function removebutton1 (event:MouseEvent){
       trace (listbox1.selectedIndex)
       listbox1.removeItemAt(listbox1.selectedIndex)
      function traceItemsnpF(a:Array):void{
    for(var i:int=0;i<a.length;i++){
    for(var s:String in a[i]){
    trace(s,a[i]+":"+a[s]);
    thank you for the replay

Maybe you are looking for

  • Visual Studio 2008 Crashes when I click on the [Main Report Preview] button

    I started with Crystal Reports Basic that is bundled with Visual Studio, and then downloaded and installed the free trial of Crystal Reports Developer 2008, and the Visual Studio Integration Manager, the issue has not been affected. After adding a cr

  • Logical hostname netmask

    I evaluate a Solaris cluster (x86_64). I want to evaluate "High availability mysql database replication with solaris zone clsuter" -from sun BluePrints .... and I have a problem with netmask for logical hostname. Cluster set ths for "C class" (dec: 2

  • Photocast access with other browsers!

    Hi All, According to Apple when you create a Photocast you can veiw with any browser capable of reading RSS on Windows or Mac. Well on my Windows box I have tried Mozilla, Firefox and Exploder, with no luck. I use Firefox with the Wizz RSS extension

  • Safari add-on / download?

    Is there a Safari add-on which will allow me to use a US IP address when travelling and connecting overseas?

  • Importing databases

    How do I import data, infact an entire database for that matter, from MySQL to Oracle? Is it using the migration tool? Whatever the method, somebody kindly brief me through it. null