Results 1 to 4 of 4

Thread: list problem

  1. #1
    fareez is offline Member
    Join Date
    Jun 2007
    Posts
    2
    Rep Power
    0

    Default list problem

    let say i have a lists of name
    michael
    john
    sarah


    then i put it into array
    User userList[] =new User[];

    then i create loop to print that list
    for (int i=0; i<userList.length; i++;){
    listbox1.setItems(userList[i]);

    anybody know how to modified this code if want to test every name if it have a condition like this:

    michael is resident for apartement A
    john n sarah are resident for apartment B

    so i think i want to use if..else but i don't know how to code that..plz anybody help me...

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    hi fareez,

    Please put your code inside [code] tags next time. That will be easier to read and correctly printed on the page.

    Regarding your question:

    You can keep two other integer arrays, one for apartment A and one for apartment B.

    And assign index of each of your users to this arrays. So if "Michael is resident for apartment A" and index of Michael in userList is 1, then write the following in your initialization code:

    Java Code:
         apartmentA[0] = 1;
    Then for this query: "is michael resident for apartement A", you will search apartementA array for the index of michael which was 1. If you find that, return true else false.

    Let me know if something is unclear.

  3. #3
    fareez is offline Member
    Join Date
    Jun 2007
    Posts
    2
    Rep Power
    0

    Default

    i already write a code like this.Is my coding right?:

    Java Code:
    PropertyInfo pInfo = PropertyInfoDAO.loadPropertyInfoByORMID(this.getSessionBean1().getPropertyID());
               
                   User[] userList = UserDAO.listUserByQuery(null,null);
                   Option[] optUser = new Option [userList.length];
         
                          int y = 0;
                            for (int i=0; i<userList.length; i++){
                                if (userList[i].inCharge.contains(pInfo)){
    [CENTER]//condition[/CENTER]
    
                                   else {
    [CENTER]//condition[/CENTER]

    i query apartment id using below code:
    Java Code:
    PropertyInfo pInfo = PropertyInfoDAO.loadPropertyInfoByORMID(this.getSessionBean1().getPropertyID());
    Actually i have 2 pages which is the previous page have a list of apartment.I create link for apartment name,then when i click that link,such as i click link for apartment A,it will go to the next page which contains a residents list for apartment A.

    I put resident list in listbox component.I use 2 listboxes. I name it listbbox1 and listbox2.If michael is resident for apartment A,his name will appear in listbox1 and john and sarah will appear in listbox2 because they are not resident for aparment A.

    The case is same for apartment B. Sarah and Michael will appear in listbox1 but michael will appear in listbox 2 becase michael is not resident for apartmentB

  4. #4
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    Hmm, sorry i am not experienced with Java EE. You might try asking this on one of the Java EE subforums. You can find more people to answer.

Similar Threads

  1. List and ArrayList
    By ravian in forum New To Java
    Replies: 3
    Last Post: 07-27-2011, 05:05 PM
  2. Members List
    By Eranga in forum Suggestions & Feedback
    Replies: 11
    Last Post: 01-17-2008, 10:41 AM
  3. Array List Problem
    By khamuruddeen in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 08:10 AM
  4. list
    By Zensai in forum New To Java
    Replies: 3
    Last Post: 11-20-2007, 07:22 AM
  5. How to get the max value from a list
    By osval in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 05:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •