Finding 'N'  Maximum object from a list.

Hi,
Collections.sort(list,comparator), will sort all the elements in the list. Whereas it is waste of resource in my case.
I need to find only top N1 from the collection. Is there any way?
Assume I may pass list which contains 10000 elements but I need a list which contains only top 10 elements.
so that I can access like..
List MaxList = Collections.sort(list, comparator, 10);
If it is not in java, Is there any possible open source library for this.
Regards
Mohan

If you don't need repeated extracts of different lenghts, then a simpler solutions that is only O(n) is possible than the ones mentioned in the other thread.
Simply iterate over the source set, maintaining a bucket of the 10 top elements found so far. For each source element, compare its value to the lowest in the bucket, and replace it if it's greater.
If the source set changes alot, it can make sense to maintain the bucket in parallel.
(This approach is probably only appropriate if the bucket size doesn't vary much and the bucket size is significantly smaller than the source set.)

Similar Messages

  • Error while activating the object from change list in IR

    Hi Friends,
    I am trying to activate a mapping object taken from History.But I am getting error "version management was unable to execute the last action because temporary internal lock has been set" while activating from change list.
    Regards,
    Suresh.

    Hi Suresh,
    have a look at the integration builder start jsp. There is a Link "Administration". On this page, on the left side, you can click on "lock overview" and check if your object is locked. Then you can remove this lock.
    Best Regards
    Sven

  • To find Missing DB Objects from one schema,sid to other schema,sid

    Hi Friends..
    I have an requirement as bellow...
    Recently we migrated from one schema to other ,some of the DB objects are missed while migrating.
    After Migration now the schema and SID are Different for newly created schema
    while comparing the newly created schema2 with old schema1 found that some of the DB objects are missed.
    So i need to find out the difference's from Schema1 to Schema2.
    But now schema 2 is having different sid and schema name and to make the changes in schema2 with respect to schema1.
    Please let me know how to go ahead with this....
    Thanks in advance...

    Hi,
    Here's one way:
    SELECT     object_name
    ,     object_type
    FROM     all_objects
    WHERE     owner     = 'SCHEMA1'     -- Case-sensitive
        MINUS
    SELECT     object_name
    ,     object_type
    FROM     all_objects
    WHERE     owner     = 'SCHEMA2'     -- Case-sensitive
    ;Use a database link for one half of the MINUS, if necessary.
    This will not detect objects that have the same name and type, but are different. For example, if both schemas have a table called TABLE_X, the query above will not display TABLE_X, even if the two tables have different rows and/or columns.

  • Algorithm to find non repeating number from the list

    Hi,
    Can anybody provide me the algorithm for the program:
    User has provided a list of 'n' numbers (0-9) with only a single number not repeating at all and rest may repeat odd or even number of times. Now, job is to find out the number which is occuring only single time without repetition....

    Hi
    If n is a smallish number, then something like
    int bins[10];
    memset bins to zero;
    for (int i = 0; i < n; ++i)
    ++bins[arrayDigits[i]];
    for (int i = 0; i < 10; ++i)
    if (bins[i] == 1)
    printf("digit is %d\n", i);
    /* break if certain that i is the only bin == 1 */
    break;
    (arrayDigits is an array of the 'n' digits).
    If n is large, then you'll probably want to break out of that first loop as soon as only one of the bins.
    unsigned flag;
    unsigned first = 0US;
    unsigned second = 0US;
    for (int i = 0; i < n; ++i)
    flag = 1U << arrayDigits;
    if (first & flag)
    if (!(second & flag))
    /* second occurence of digit */
    second |= flag;
    /* exit condition is that 'first' has all bottom 10 bit set and
    'second' has all but 1 of the bottom 10 bits set */
    if (first == 0x3ff)
    /* all 'first' bits set */
    switch (second)
    case ~(1U << 0): /* digit is 0 */
    case ~(1U << 1): /* digit is 1 */
    case ~(1U << 9): /* digit is 9 */
    printf("digit is %d\n", i);
    break;
    default:
    /* do nothing - more than one digit still not at 'first' */
    /* else already seen 2 or more of digit */
    else
    /* first occurence of digit */
    first |= flag;
    I haven't tested any of the code.
    Paul

  • How to find a specific word (from a list) in a sentence located in a different table, and build a column that contains the name

    Hi all, 
    I have 2 tables:
    1) Lookup table- "Names"- which contains ID# and product description (~100 names that can change).
    2) Data table- "Data"- which contains a column with sentences and within lies also the description. In addition, there is a quantity column.
    Example:
    Names table-
    ID
    Name
    1 Glass
    2 Paper
    3 Alum'
    4 Metal for construction
    100 Hydro therapy products
    And Data table-
    Description
    Qty
    Someone went to use the machine. 1.80 cm, Alum', for the rest of the day
    6
    Metal for construction is the major component in our system
    7
    <gs class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="ba668f16-4de8-41d9-af39-d1b17422d6fe" id="ae5b76e8-6897-46c8-823b-86a382087f83">Kandoo</gs>, Delgado,
    Glass 17
    Greece needs more paper, 200 ft.
     45
    *there is no order where the lookup value can be found in the sentence*
    My purpose is to import the Data table while performing a calculation, that <gs class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="1941bde7-1595-40eb-9d64-c2e3b9fabdef" id="b60549fc-5b92-46ea-abc6-72cc8c4c093b">checks</gs>
    for each row what is the suitable lookup value and then add it to a new column "Name". 
    Meaning, this table should be the new data after import:
    <gs class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="f5d9da98-3ff6-4022-920d-8965a15730ee" id="580f945f-7822-4035-9b5b-542c74eff605">Description</gs>
    Qty                        
    Name
    Someone went to use the machine. 1.80 cm, Alum', for the rest of the day
    6 Alum'
    Metal for construction is the major component in our system
    7 Metal for construction
    <gs class="GINGER_SOFTWARE_mark" ginger_software_uiphraseguid="365dd7f8-7ffc-4ef3-95bf-9bf03421c90d" id="c9ba8515-3dba-4a6b-929e-650510f70844">Kandoo</gs>, Delgado, Glass
    17 Glass
    Greece needs more Paper, 200 ft.
     45 Paper
    Appreciate all support! 
    I lost hope and I want to avoid macros as much as possible.
    Thanks!
    עמית

    Hi Amit,
    I updated the file. The solution uses the following query formula:
    let
    Source = Excel.CurrentWorkbook(){[Name="DataTbl"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Custom", each IndexTbl),
    #"Expand Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Scope"}, {"Scope"}),
    #"Filtered Rows" = Table.SelectRows(#"Expand Custom", each Text.Contains([Description], [Scope])),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Topic", "Component Code", "Project", "Date", "TotalQty", "TotalQtyActual", "ID", "SOW #", " SOW#(lf)Rev", "Scope Driver", "Scope Source", "Scope Source #", "Cost Code", "Type", "Bdg", "System Code", "IMF Number", "IMF Description", "WG", "C or NC", "C/e", "LLE", "Dwg Ref", "Comments ", "Description", "Size", "Qty", "Unit", "Materials Cost/Unit ", "Sub-Total per Unit €", "Unit Rate ", "Total", "DIV Code", "SYS Code", "HelperForDynfilter"}, {{"Scope", each Text.Combine([Scope], " | "), type text}})
    in
    #"Grouped Rows"
    It is based on two queries. The first is the import from table of "IndexTbl", the second is the import of "DataTbl' which is then extended according to the expression above.
    Hope this helps.
    Gil

  • 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()

  • Can I create a network object from CIDR format or do I need to use IP - netmask?

    Have a cisco ASA running ASA V 8.3
    Wondering what the correct syntax is or even if it is possible to create a network object from a list of IP's in CIDR format? 
    Typically just do this:
    Create network-object
    object-group network name
    network-object 1.2.3.0 255.255.255.0
    Would like to do this: 
    network-object 1.2.3.0/24
    thanks!

    Hi,
    As far as I know the ASA does not support entering a network/subnet mask in such format in any of its configurations.
    - Jouni

  • Problem in jni getting object from methodst

    a want to save an object gatin from java and save it into my list in c code
    my probleme is when a call getobject more than one times it return null (in the first one it return the last object saved)
    i dont understand why
    this is my methods
    to add object in my list
    NIEXPORT void JNICALL Java_Matrice2_ajoutercell
    (JNIEnv *env, jobject obj, jint lig, jint col,jobject objectadded){
    AjouterCellule(objectadded ,lig,col,recupererAdresse(env,obj));
    // this is a method created to save the ovject in my list
    // ( in Ajoutercell a save my object like this
    List->element = val;
    struct list {....
    jobject val
    ]*list;
    the code work good if i use jint
    --- and this is the method to getobject
    JNIEXPORT jobject JNICALL Java_Matrice2_Getcell
    (JNIEnv *env, jobject obj , jint lig, jint col){
    return recuperercell(recupererAdresse(env,obj),lig,col);
    // the method recuperercell get the object from my list
    return List->valr;
    i hope that some one can understand my code and help me
    thanks ...

    i use newglobalref and it work ; but i have to delete every ref created when i delete or modify an object
    thanks to you

  • How can I get a List Objects from my NameSpace

    Hello to All.
    I need a list of objects an specifc documentation about these. ( SAP XI)
    Any transaction o maybe tables , where located this objects .
    Thanks and Regards
    Edited by: Luis Ortiz on Oct 10, 2008 2:58 PM

    Location of XI objects in R/3.
    Please find the repository APIu2019s in the SE24 class builder that can be used for accessing repository objects from the ABAP stack of SAP XI. Check CL_SRAPI* in the SE24 transactions for digging further.
    location of interface objects
    CL_SRAPI_DATA_TYPE---data type
    CL_SRAPI_DATA_TYPE_ENH---data type enhancement
    CL_SRAPI_FAULT_MESSAEG_TYPE--fault message type
    CL_SRAPI_MESSAGE_TYPE--message type
    CL_SRAPI_INTEGRATION_SCENARIO--integration scenario
    chek this blog for more info
    Ripping off SAP XI Stack …Sharing the goodies of ABAP API’s..!!
    Regards,
    Sarvesh

  • How do I get to the screen in Mail that allows you to delete multiple "Previous Recipients"  from the list? I have seen it but cannot find it again. Help.

    How do I get to the screen in Mail that allows you to delete multiple "Previous Recipients"  from the list? I have seen this screen but cannot find it again. It shows all of the "Previous Recipients" in a long list. You can edit the list by selecting multiple names or all names with the command key and delete. Help.

    Launch the Mail app on your Mac and go to Window>Previous Recipients.

  • How to show data from sharepoint list in mm dd yyyy format using Server Object Model

    In SharePoint 2010
    List "Employee", Colum Name "JoinDate" 
    has stored data in  (01/31/2014 12.00 PM) mm\dd\yyyy hr:mm PM format.
    How to display this data in mm\dd\yyyy only using C# on custom web part?

    //Write the code to read your list item
    SPListItem item = list.Items[0];
    //Get a DateTime object with the list column value
    DateTime date = Convert.ToDateTime(item["Date Column Name"]);
    String strDate = date.ToString("mm-dd-yyyy hh:mm tt");
    //you can also try ("dd/mmm/yyyy")
    http://sharepoint.stackexchange.com/questions/12820/safest-way-to-get-a-date-from-sharepoint-into-a-c-datetime-field-using-object

  • UnsupportedOperationException Error while removing object from List

    Hi,
    I need to remove a set of objects from List if it contains similar objects as the other one.
    Follwing is the code snippet of the above scenario...
    List selectedPaxList = new ArrayList();
    TreeSet seatAssignedPaxlist= new TreeSet();
    selectedPaxList.add("1");
    selectedPaxList.add("2");
    selectedPaxList.add("3");
    seatAssignedPaxlist.add("1");
    seatAssignedPaxlist.add("2");
    if(selectedPaxList.containsAll(seatAssignedPaxlist))
    selectedPaxList.removeAll(seatAssignedPaxlist);
    If i do this in java program it executes fine without any error.But if I do the same in JSP I am getting the following error......
    java.lang.UnsupportedOperationException
    at java.util.AbstractList.remove(AbstractList.java:167)
    at java.util.AbstractList$Itr.remove(AbstractList.java:432)
    at java.util.AbstractCollection.removeAll(AbstractCollection.java:351)
    Plz... help me to resolve the issue

    java.lang.UnsupportedOperationException
    at
    java.util.AbstractList.remove(AbstractList.java:167)
    at
    java.util.AbstractList$Itr.remove(AbstractList.java:43
    2)
    at
    java.util.AbstractCollection.removeAll(AbstractCollect
    ion.java:351)
    That stack trace looks wrong to me.
    ArrayList overrides the remove method, so it
    shouldn't be using the method in AbstractList. That's what I thought, too. There is either something missing or it's not an ArrayList. In fact the javadoc of AbstractList.remove sais:
    "This implementation always throws an UnsupportedOperationException."
    So it really looks like another subclass is used.
    Also
    the object it is trying to remove is a list (from
    your exmaple it should be a String)
    I could be wrong.These are just the code references not the parameters, I think.
    -Puce

  • More than maximum 5 filtered album lists trying to register. This will fail,Why i am getting this error when i pick video from Photo library.

    I am able to pick 4 videos from the Photo library in my iPhoneAPP but when i try to pick 5th one it throws an error:
    "More than maximum 5 filtered album lists trying to register. This will fail,Why i am getting this error when i pick video from Photo library."

    Hello Tate r Bulic
    I don't have any idea how to remove this error,can i pick more than 5 videos from the photo library...
    If it's then please help me and gimme idea..Thanks

  • Using OS X 10.6.8 on my IMac, I find that items on my message list no longer "fade" from dark to light when I click on them. I recently switched the font from Arial to Helvetica to permit me to select italics for any word. I am composing in rich text.

    Using OS X 10.6.8 on my IMac, I find that items on my message list no longer "fade" from dark to light when I click on them. I recently switched the font from Arial to Helvetica to permit me to select italics for any word. I am composing in rich text.

    Not sure why it would default to IMAP?  But any how, start the account anew, fill in the first page of info, but before clicking on the Create button, hold down the Option key until the Create button changes to read Continue.  Click continue, and proceed in a more manual process during which you can set the account type as POP.
    Ernie

  • TS2756 For a USB connection for a personal hotspot I am requested to "Choose iPhone from the list of network services".  Where do i find this list?

    For a USB hotspot connection I am requested to "Choose iPhone from the list of network services".  Where do I find this list?

    Perhaps it would be helpful for you to view the page source code of this page
    http://www.alanwork.com/
    As you can see, the submenu code links are immediately below the top level code, and are
    wrapped in their own  <UL> </UL> tag pairs.
    Hope that helps

Maybe you are looking for