About collections

hello everybody,
My question is "What is a 'collection' in java"? Please explain with an example.

Can someone explain how to enter nice looking links that don't show the URL (example in previous reply)? I sent this question to the forum administrators, but they never answered. The "Formatting Tips" explanation doesn't cover this (URL in their example is not hidden)

Similar Messages

  • About Collection and ForAll

    Dear Guru
    1) I have some documents about collection of 10g
    and example of Forall function.
    2) Question: I have procedure called Test_ps
    How to see the source code of the procedure
    A : User_source
    But i want to see how my parameter are there in procedure is there any option ?
    Advance Thanks..

    you can use DSEC <Procedure_Name> to see the list of arguments
    PRAZY@11gR1> create or replace procedure test_proc(a number,b number) is
      2  begin
      3  null;
      4  end;
      5  /
    Procedure created.
    Elapsed: 00:00:00.01
    PRAZY@11gR1> select text from user_source where name='TEST_PROC' order by line;
    TEXT
    procedure test_proc(a number,b number) is
    begin
    null;
    end;
    Elapsed: 00:00:00.01
    PRAZY@11gR1> desc test_proc;
    PROCEDURE test_proc
    Argument Name                  Type                    In/Out Default?
    A                              NUMBER                  IN
    B                              NUMBER                  INRegards,
    Prazy

  • Book excerpt about Collections

    http://java.sun.com/developer/Books/javaprogramming/javaobjects/ch06final.pdf
    Nowhere in this free chapter does the author advise to declare Collections by specifying the least specialized type possible
    it's always something like :
    ArrayList arrayList = new ArrayList();
    // using Collection methods only, like "add()"...By doing so, aren't we losing one of the most interesting aspect of Collections : designing by contract and being able to swap implementations as the needs change ?
    Do you think this is irrelevant in a chapter about collections but belongs to a pure OO chapter ?
    Just wondering...

    I've only skipped the chapter, so I might miss anything. But I'll give you my two Euro-Cents nevertheless:
    - I think it should be mentioned in the chapter, even 'though that chapter obviously is not about that specific concept. More importantly the chapter should really use that paradigm throughout it's example code. I think in this case giving correct examples is much better than repeating the message again and again.
    - The chapter does mention using a simple wrapper about the list to hide away the use of the concrete list implementation in favour of a more business-orientet interface (Transcript+TranscriptEntry vs. ArrayList<TranscriptEntry>). IMO that is another approach to the same "problem".

  • [CS3 JS] Question about collecting overridden style settings

    Hi!
    I can use the styleOverridden to check every item in a textStyleRange for overrides. But is there a smart way to collect the attributes actually overridden? (The attributes showing up neatly in the tooltip when you hold the mouse cursor over an overridden style name.)
    My script needs to add a clean character style for every overridden style, recreating the behaviour of the add new character style dialogue, creating the new style based on the overrides.
    Kind regards,
    Andreas

    Ah, it looks like it's beginning to work now :-)
    I thought I had tried some of these things before, but obviously not. Thanks Peter, for your assistance. Now even assigning the whole properties collection of the TextStyleRange objects to the new character style object works! There's a lot of properties created, which I'd really would have preferred not to show up (in the summary of the character style dialogue box), since they are (as far as I can see) the default values, but I like the easy code this approach results in:
    var selText = app.selection;
    var srs = selText[0].textStyleRanges;
    for (var iTSR=srs.length-1; iTSR>=0; iTSR--){
    ]if (srs[iTSR].styleOverridden){
    ]]// This is an overridden style we need to create a style for
    ]]var ch = srs[iTSR];
    ]]newStyle = app.activeDocument.characterStyles.add(ch.properties);
    ]]if (app.activeDocument.characterStyles.item('newstyle'+iTSR.toString())!=null) app.activeDocument.characterStyles.item('newstyle'+iTSR.toString()).remove();
    ]]newStyle.name = 'newstyle'+iTSR.toString();
    I'm not yet quite clear on how to treat overridden paragraph styles. Perhaps I need to check whether the properties of the new character style are already the same as the ones of an possibly applied paragraph style, and if so, not assign (or remove) that property from the new character style.
    Also... possible need to name all uniquley auto-generated styles and find a way to apply the same style again (not to risk creating a large number of character styles just setting "bold").
    Andreas

  • Question about Collection

    Hello!!
    My boundary is based on AD Sites and my System Discovery is configured to discovery All Forest.
    When i try create a Collection based on IP Subnet 10.12.0.0, the collection retrieves only 2 computers but the subnet have more than 200 computers.
    The IP Subnet 10.12.0.0 is NOT registered in AD Sites and Services... this is a problem? How to solve?
    My query in Collection:
    select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.IPSubnets = "10.12.0.0"
    Thanks!!
    Atenciosamente Julio Araujo

    If you've done your homework on your network, you should have a map of subnets to ranges so that you know what IPs are covered all around.
    That being said, If you MUST use IPs, I'd use IP ranges instead.
    If your environment is constructed simply, such as straight Class Bs or Cs, this is pretty easy with code such as this:
    select
    SMS_R_SYSTEM.ResourceID,
    SMS_R_SYSTEM.ResourceType,
    SMS_R_SYSTEM.Name,
    SMS_R_SYSTEM.SMSUniqueIdentifier,
    SMS_R_SYSTEM.ResourceDomainORWorkgroup,
    SMS_R_SYSTEM.Client
    from
    SMS_R_System
    WHERE
    SMS_R_System.IPAddresses LIKE "10.100.25.%"
    If your environment is supernetted, you may need to have a LIKE statement such as this:
    WHERE
    SMS_R_System.IPAddresses LIKE "10.100.7[2-9].%"
    Lastly, if your environment is supernetted, AND runs across 10s ranges, such as 10.100.208.1 - 10.100.215.254, you'll need to adjust because of some SQL restrictions on these types of queries:
    where
    SMS_R_System.IPSubnets like '10.100.20[8-9].0'
    or
    SMS_R_System.IPSubnets like '10.100.21[0-5].0'
    Hope this helps.

  • About Collect Statement.

    hi experts,
         i am genereating a report in FICO module. i have to fetch teh data from the field DMBTR (AMOUNT). it has both credits anddebits. i have to do calculations and should display the final balance in the report. each GL account number has different credits and debits. i have to display each account with the balance. if i am using collect statement it only making sum of eitehr debits or credits. i want both to be sum up. is tehre any other way to do the same..thnx in advance,
                                   santosh.

    Syntax Diagram
    COLLECT
    Syntax
    COLLECT wa INTO itab [result].
    Effect
    This statement inserts the contents of a work area wa either as single row into an internal table itab or adds the values of its numeric components to the corresponding values of existing rows with the same key. As of Release 6.10, you can use result to set a reference to the inserted or changed row in the form of a field symbol or data reference.
    Prerequisite for the use of this statement is that wa is compatible with the row type of itab and all components that are not part of the table key must have a numeric data type (i, p, f).
    In standard tables that are only filled using COLLECT, the entry is determined by a temporarily created hash administration. The workload is independent of the number of entries in the table. The hash administration is temporary and is generally invalidated when the table is accessed for changing. If further COLLECT statements are entered after an invalidation, a linear search of all table rows is performed. The workload for this search increases in a linear fashion in relation to the number of entries.
    In sorted tables, the entry is determined using a binary search. The workload has a logarithmic relationship to the number of entries in the table.
    In hashed tables, the entry is determined using the hash administration of the table and is always independent of the number of table entries.
    If no line is found with an identical key, a row is inserted as described below, and filled with the content of wa:
    In standard tables the line is appended.
    In sorted tables, the new line is inserted in the sort sequence of the internal table according to its key values, and the table index of subsequent rows is increased by 1.
    In hashed tables, the new row is inserted into the internal table by the hash administration, according to its key values.
    If the internal table already contains one or more rows with an identical key, those values of the components of work area wa that are not part of the key, are added to the corresponding components of the uppermost existing row (in the case of index tables, this is the row with the lowest table index).
    The COLLECT statement sets sy-tabix to the table index of the inserted or existing row, in the case of standard tables and sorted tables, and to the value 0 in the case of hashed tables.
    Outside of classes, you can omit wa INTO if the internal table has an identically-named header line itab. The statement then implicitly uses the header line as the work area.
    COLLECT should only be used if you want to create an internal table that is genuinely unique or compressed. In this case, COLLECT can greatly benefit performance. If uniqueness or compression are not required, or the uniqueness is guaranteed for other reasons, the INSERT statement should be used instead.
    The use of COLLECT for standard tables is obsolete. COLLECT should primarily be used for hashed tables, as these have a unique table key and a stable hash administration.
    If a standard table is filled using COLLECT, it should not be edited using any other statement with the exception of MODIFY. If the latter is used with the addition TRANSPORTING, you must ensure that no key fields are changed. This is the only way to guarantee that the table entries are always unique and compressed, and that the COLLECT statement functions correctly and benefits performance. The function module ABL_TABLE_HASH_STATE can be used to check whether a standard table is suitable for editing using COLLECT.
    Example
    Compressed insertion of data from the database table sflight into the internal table seats_tab. The rows in which the key components carrid and connid are identical are compressed by adding the number of occupied seats to the numeric component seatsocc.
    DATA: BEGIN OF seats,
            carrid   TYPE sflight-carrid,
            connid   TYPE sflight-connid,
            seatsocc TYPE sflight-seatsocc,
          END OF seats.
    DATA seats_tab LIKE HASHED TABLE OF seats
                   WITH UNIQUE KEY carrid connid.
    SELECT carrid connid seatsocc
           FROM sflight
           INTO seats.
      COLLECT seats INTO seats_tab.
    ENDSELECT.
    Exceptions
    Catchable Exceptions
    CX_SY_ARITHMETIC_OVERFLOW
    Cause: Overflow in integer field during totals formation
    Runtime Error: COLLECT_OVERFLOW
    Cause: Overflow in type p field during totals formation
    Runtime Error: COLLECT_OVERFLOW_TYPE_P
    Non-Catchable Exceptions
    Cause: COLLECT used for non-numeric fields
    Runtime Error: TABLE_COLLECT_CHAR_IN_FUNCTION

  • Questions about Collections.shuffel and error message

    I am trying to get my poker game to work but it comes up with an error when it trys to score the hand
    *public class PokerTester{*
    Deck deck *=* new Deck*();*
    public PokerTester*()*
    playGame*();*
    public void playGame*()*
    *{*+//stacks hand+
    Hand hand *=* new Hand*();*
    for(int i*=* 0*;* i*<* 5*;* i*++)*
    hand*.*add*(*deck*.*getTopCard*());*
    System*.*out*.*println*(*"Player's Hand:"*);*
    hand*.*showHand*();*
    public static void main*(*String*[]* args*)*
    new PokerTester*();*
    public class Hand*{*
    ArrayList<Card> hand=new ArrayList<Card>();
    int[] values = new int[5];
    public void add(Card card)
    hand.add(card);
    +
    public String getHandValue()
    +
    String win= "";
    for(int i= 0; i<5; i++)
    *values=values[((Card)hand.get(i)).getValue()];*
    Arrays.sort(values);
    if(checkRoyalStraight()&&checkFlush()) win="Royal Flush";
    else if(checkFlush()&&checkStraight()) win="Straight Flush";
    else if(checkOfAKind(4)) win = "4 of a Kind";
    else if(checkFullHouse()) win = "Full House";
    else if(checkFlush()) win = "Flush";
    else if(checkStraight()) win = "Straight";
    else if(checkOfAKind(3)) win = "3 of a Kind";
    else if(checkOfAKind(2)) win = "Pair";
    else win = "High Card";
    return win;
    +
    public boolean checkOfAKind(int n)
    +
    boolean kind=false;
    if(n==4)
    if(values[0]==values[3]||values[1]==values[4])
    kind=true;
    if(n==3)
    if(values[0]==values[2]||values[1]==values[3]||values[2]==values[4])
    kind=true;
    if(n==2)
    for(int i=0; i<4; i++)
    *if(values[i]==values[i+1])*
    kind=true;
    return kind;
    public boolean checkFullHouse()
    boolean fullhouse=false;
    if(values[0]==values[2]&&values[3]==values[4])
    fullhouse=true;
    else
    if(values[2]==values[4]&&values[0]==values[1])
    fullhouse=true;
    return fullhouse;
    public boolean checkFlush()
    int suit = ((Card)hand.get(0)).getSuit();
    for(int i=1; i<5; i++)
    if(((Card)hand.get(i)).getSuit() != suit)
    return false;
    return true;
    public boolean checkStraight()
    int count=0;
    for(int i=0; i<4; i++)
    *if(values[i]+1==values[i+1])*
    count++;
    if(count==4)
    return true;
    else return false;
    public boolean checkRoyalStraight()
    int n=10;
    for(int i=0; i<5; i++)
    *if(values[i]==10)*
    n++;
    if(n==15)
    return true;
    else return false;
    +
    public void showHand() +
    +
    +
    for(int i= 0; i<5; i++)
    int suit=hand.get(i).getSuit();
    String s="";
    if(suit==0)
    s="Hearts";
    else if(suit==1)
    s="Spades";
    else if(suit==2)
    s="Clubs";
    else s="Diamonds";
    System.out.println(((Card)hand.get(i)).getValue()+" of "+s);
    System.out.println("Hand value: "+getHandValue());
    public class Deck
    Card*[]* cards *=* new Card*[*52*];*
    ArrayList*<*Card*>* deck *=* new ArrayList*<*Card*>();*
    public Deck*()*
    for(Integer i*=*0*;* i*<*4*;* i*++)*
    for(Integer n*=*1*;* n*<=*13*;* n*++)*
    deck*.*add*(new* Card*(*n*,* i*));*
    +
    Collection*.*shuffle*(*deck*);*
    +
    public Card getTopCard*()*
    Card topCard *=*deck*.*get*(*0*);*
    deck*.*remove*(*0*);*
    return topCard*;*
    public class Card*{*
    private int value;
    private int suit;
    public Card(int value,int suit)
    this.value=value;
    this.suit=suit;
    public int getValue()
    return value;
    public int getSuit()
    return suit;
    {color:#000000}
    This is what i get when I run the program{color}
    1 of Hearts
    2 of Hearts
    3 of Hearts
    4 of Hearts
    5 of Hearts
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
    at Hand.getHandValue(Hand.java:22)
    at Hand.showHand(Hand.java:145)
    at PokerTester.playGame(PokerTester.java:16)
    at PokerTester.<init>(PokerTester.java:6)
    at PokerTester.main(PokerTester.java:21)
    Also I cannot get the Collections.shuffle() to work correctly does anyone know how to use this properly, Thank you

    When you use the letter "i" for an array index without using the code tags, the forum interprets that to mean "start italic" and your code is mangled - converted to italic and changed.
    Repost using code tags:
    [code]
    Put your code here
    [/code]
    This error
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5means that an array index value is greater than the max value allowed for the array.
    If you can't fix this, identify the line where the error is happening (it's line 5)

  • About 'Collective No' in Transaction ME22(Not ME22N)

    Hi,
    I could find the Collective No' in tab 'Additional data' of transaction Me22N, But i didnt not find it in ME22.
    Do you know from where i could check the Collective No in ME22 transaction??
    Thank you very much

    Hi,
    Sorry, I dont think its available in the ME22 screen layout.
    You can get the Quotation date and Quotation No. from header details in ME22, but not the collective No.
    This could be an enhancement in ME22N,
    Regards
    Merwyn

  • About collecting java and JVM-System

    Hi all,
    I'm trying to collect from a java application (jvm is 1.6). When I see the exclusive time per function I get most of the time assigned to <JVM-System>. My questions are:
    1. what jvm activites get mapped to this? gc? jitting?
    2. any way to get finer granularity in this jvm activity?
    many thanks in advance,
    fdo

    Sorry, this was a self inflected RTFM ;)
    http://docs.sun.com/app/docs/doc/819-5264/6n7c1asni?a=view#afaoj

  • About Collections class

    The Collections Framework defines several algorithms that can be applied to collections
    and maps.These algorithms are defined as static methods within the Collections class.
    These algorithms support List,Map,Set,Enumeration,SortedMap,SortedSet.But not
    Iterator.
    Is it fixed by Java that no Iterator can use within any of those algorithms of Collections
    class?
    Or, Is it only Maps class support Iterator for it's algorithms?

    Thanks everybody for replies.
    import java.util.*;
    public class AlgorithmsDemo {
         public static void main(String[] args) {
              LinkedList<Integer> ll=new LinkedList<Integer>();
              System.out.println("Size of LinkedList ll: "+ll.size());
              System.out.println("Contents of LinkedList ll: "+ll);
              ll.add(-8);
              ll.add(20);
              ll.add(-20);
              ll.add(8);
              System.out.println("Now the size of linkedList ll: "+ll.size());
              System.out.println("Now the contents of linkedlist ll: "+ll);
              Comparator<Integer> comp=Collections.reverseOrder();
              Collections.sort(ll,comp);
              System.out.print("List sorted in reverse: ");
              for(int i:ll)
                   System.out.print(i+" ");
              System.out.println();
              Collections.shuffle(ll);
              System.out.print("List shuffled: ");
              for(int i:ll)
                   System.out.print(i+" ");
              System.out.println();
              System.out.println("Minimum: "+Collections.min(ll));
              System.out.println("Maximum: "+Collections.max(ll));
    }If I want to use Iterator instead of Comparator then what changes need to do
    within above code?

  • Some questions about Collections

    getItem(index or name): when to throw an exception when to return null?
    getIndex(Item): when to return -1 when exception?
    Is it better to have two versions of a method?

    What if I pass in -1 as the index?
    What if there are 10 items and I pass in 100,000?jschell,
    The choice to throw an exception or to return null is
    dependent on the application. If the container so
    feels that -1 or 10,000 shall impair its functionality
    or has impaired its functionality and it cannot
    recover from it - by all means, go ahead and throw
    your exception.Certainly. But the question wasn't addressing a specific application but rather a single component.
    Given that my presumption would be to write the component based on the standpoint of a library and not an application.
    That means that the component must make a decision based on correctness for the component, which is obvious since it can't do it based on correctness of the application.
    This would suggest that if a index is passed in that exceeds the boundaries of the collection that throwing an exception is the correct decision. Because it exceeds the correctness of the average collection. Naturally that might not be true for a specific kind of collection, but the question wasn't addressing a specific kind of collection.
    >
    Vector is just an instance of a type of container - no
    body stops you from creating your own container and
    also in Vector - please notice that both are
    RuntimeException.
    Yes Vector uses a unchecked exception for boundary problems. Which one could take to suggest that in the general case that is a good idea.
    In the ultimate equation, it is the form that you
    chose that shall dictate wether you return null or
    throw an Exception. There is nothing absolute in this
    matter. My point was more subtle (to point to you, if
    you have failed to notice) - "Do not throw Excception,
    until you are sure that you cannot recover from the
    problem and proceed correctly".I agree there are no absolutes. But I also think that when boundary conditions are exceeded in libraries then exceptions should be used most of the time. I believe most third party libraries take this stance. As an alternative sometimes they also provide a checked and unchecked versions which allows the user to decide the best recourse.

  • Basic questions about permanent Collections

    I am just learning about Collections, discovering that a Collection preserves all of the work I done in the collection. I am assuming then, that the images in a collection are virtual copies that can be adjusted in the Develop Module to be different than they would be displayed in the general catalog under the original imported folders. I also assume that a modified image cannot be locked to prevent further changes, say if another virtual copy were to be made.
    I gather that Collections need to be protected somehow, for instance if I have one collection with images adjusted to look good on the web, and another collection of the same images adjusted to look good using a certain printer.
    Maybe I will never need to adjust images for different applications, except outside of Lightroom for CMYK applications in offset printing. Since various settings for Slide Show, Web and for Print can all be contained in one collection, it might probably be best to use the same images without changing the images for each output.
    Can some of you who are more experience add thoughts here to how best to use Collections. My goal is to keep things simple.
    TIA,
    Ken

    There are not enough gold stars to go around but you all deserve them for the helpful answers.
    I see on pg 175 of the Lightroom Classroom In A Book (in which there are also an unusual amount of typos) that "In the Quick Describe metadata set, the Metadata panel shows the Filename, Copy Name (if the image is a virtual copy..." This is more evidence that Lightroom and the system of Metadata is quite well developed itself, including the 'Copy Name' for a virtual copy. I have found already, in my short experience with Lightroom, that I want to work on a Virtual Copy when I'm not quite sure of the direction I want to take with a photo's adjustments. By retaining the Master 'as is' (with modest adjustments) I can always quickly go back to view the starting point (best image with modest adjustments) while I continue to work on a Virtual Copy for more experimental adjustments.
    On the one hand, my shooting is going on hold while I learn Lightroom, but I feel it is a worthwhile investment to become as familiar as possible with Lightroom's capabilities. It seems to add more to my desire to capture images more accurately, because I know I have so much to work with once I get the images back into the studio. Crisper images with optimal lighting will make me as happy as a pig in mud when I get them into Lightroom.

  • Maintenance Windows - When a client belongs to more than one collection

    Hi,
    I am a little confused with maintenance windows as I have never had to use them before. I have client that belongs to Collection A with no maintenance window, and Collection B with a maintenance window.   I typically push out apps during
    the day (after they have been tested) so I never use maintenance windows.  I am deploying an application to Collection A (no MW), but it shows in the status that it is waiting for a maintenance window. I assumes it's in this state due to me creating Collection
    B with a maintenance window because I need to push something out this weekend and can only perform this from 10pm to 2am.  If you are deploying an app to a collection, shouldn't look at the maintenance window for THAT collection, instead of
    looking at all the NW for collections a client is added to?  Is there anyway around this?
    Thanks!

    Maintenance Windows are applied to and enforced by the client agent itself. The client enforces the MWs on any and all activity it performs regardless of collection targeting. In fact, clients don't know anything about collections at all. 
    Jason | http://blog.configmgrftw.com

  • In need of help with Collections.

    Greetings,
    I've been assigned a college work where I have to develop a solution, utilizing Swing and Collections, to the problem below:
    "There is a department store with several products. The store owner doesn't know exactly how many product types there are, so he decided to register all types of products. The registering option consists of the following operations: add, remove, and change product.
    The products have three characteristics (attributes): name, quantity and price. Once all products are registered, the store owned wants to see a list of the products in alphabetical order on the screen.
    The store owner also wants the program to sell the products. The sale is done with the user searching for a product by the name, and the program will show the price of the product on the screen. The user confirms that it's the right product, and the program will reduce the item's quantity by one.
    Obs.: To simplify the problem, work with a reduced number of products. Also the program does not need to store date in the disk."
    So far I've built a class named Product, a visual class for the GUI and the main class. Inside the Product class I have a String for the name, a Float for the price, and Integer for the quantity, as well as the getters and setters for those private variables.
    In the GUI class I've made a Product Array and I also made the text fields so the user can type the data and put it in the array. This part seems to be working fine. The problem begins when using Collections. How can I use this array to make a sorted list of the products (it seemed to work when using Arrays.sort(products, byAlpha [Comparator I've creadted to sort alphabetically]), but I don't know how to work with this, now supposedly sorted, data), maybe put it inside a JList, where the user can see what products he is registering in real time? Can I make it so the user clicks on the product in the JList and he can now delete it or change the values of that product (price, quantity)?
    Any help, suggestions, insight, are greatly appreciated. Thanks in advance!
    Thiago.

    So, for example, on a JButton, I should
    write the code on a different class, and in the GUI
    class, make an instance of that class (or is it the
    other way around?), and call the method that I need
    for that button inside the actionPerformed? (Sorry if
    I sound confusing, I'm not very familiar with Java)Suppose you have a class called Store, that represents the store. Internally, it has a Collection of Products, but the caller doesn't need to know that.
    So, Store might have a method called findProducts:
    public Collection<Product> findProducts(String findThis) {
        Collection<Product> returnThis = new ArrayList<Product>;
        // code here that searches through the internal collection, and
        // adds products whose names match the search string to returnThis
        return returnThis;
    }So then you might have a GUI that looks like this:
    public class StoreGUI {
        private Store theStore;
        public StoreGUI() {
            theStore = new Store();
            // create frame, etc.
            final JTextField searchThis = new JTextField();
            JButton searchButton = new JButton("Search");
            final JList searchResults = new JList();
            searchButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Collection<Product> result = store.findProducts(searchThis.getText());
                    searchResults.setListData(result.toArray());
            // add text field, button, etc. to frame, etc.
    It may be preferable to get rid of getters and
    setters and instead have operations that are
    specifically meaningful for Products. Not sure if I understand, could you give me an
    example of how I could do that?I mean that if Product now has this:
    private int quantity;
    public int getQuantity() {
        return quantity;
    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }Then arguably that doesn't make sense, because when you run a store you can't just magically create a hundred boxes of cornflakes, which (arguably) is what you'd be doing if you did this:
    cornflakes.setQuantity(100);So it might make more sense to get rid of setQuantity, and provide methods on Product like this:
    private int quantity;
    public int getQuantity() { // this is still OK, you can always look at your inventory
        return quantity;
    public void buy(int quantity) {
        // check to make certain that quantity is no more than this.quantity
        this.quantity -= quantity;
    public void addInventory(int quantity) {
        this.quantity += quantity;
    }This might not be the best example, because the difference isn't huge. But the idea is that you're modelling reality a little more closely, and you're moving the logic that controls the state of the object, directly into the logic. (So you don't have some external object calling getQuantity, changing it, and then calling setQuantity.) This tends to make code easier to maintain.
    The book I'm using as reference gives examples
    of List and ArrayList, but only using String. I'm not
    sure how to use it for my Product class, would it be
    something like this?
    > HashSet<Product> products = new HashSet<Product>();Yes, that's exactly right.
    Also, do you happen to know any
    resource on the web where I can learn more about
    Collections?http://java.sun.com/docs/books/tutorial/collections/index.html

  • COLLECT: Which table is better to use - STANDARD or SORTED?

    Hello Performance gurus,
    I read this curious fact about COLLECT statement:
    In standard tables that are filled using COLLECT only, the entry is determined by a temporary hash administrator. The workload is independent of the number of entries in the table. The hash administrator is temporary and is generally invalidated when the table is accessed to be changed. If COLLECT statements are specified after an invalidation, a linear search of all table rows is performed. The workload for this search increases in a linear fashion in relation to the number of entries.
    In sorted tables, the entry is determined using a binary search. The workload has a logarithmic relationship to the number of entries in the table.
    In hashed tables, the entry is determined using the hash administrator of the table and is always independent of the number of table entries.
    So does this mean if we're populating a table using COLLECT we should prefer STANDARD over SORTED(due to the HASH administration)? Is there any performance overload while setting up the temporary hash administrator for STANDARD tables?
    Please enlighten me.
    BR,
    Suhas

    Actually I have just noticed I already had created a test program for this somewhere in the past.
    Here are the results:
    STANDARD            1.091.295
    SORTED              3.159.771
    HASHED                994.101
    If for the STANDARD table you somehow destroy the hash administration (in this case it was done in the beginning by APPENDing one record):
    STANDARD            2.255.905
    SORTED                 14.013
    HASHED                  8.022
    (this 2nd execution was with less rows that the 1st execution, otherwise for the standard table it would take too long).
    So this does prove that standard tables can be faster than sorted tables in that special case, but again I would not rely on that.
    Rui Dantas

Maybe you are looking for