Sort a  Generic List.

I was wondering how to sort a list of generics. I am an Experienced C++ programmer and know that I can do this with STL quite easily but cannot see an equivelant in Java.
I was expecting to have something like the following code
//perhaps an equivelant of a functional object added here in the constructor
List<String> listStrings = new Vector<String>();
listStrings.add("Hello");
listStrings.add("Cruel");
listStrings.add("World");
sort(listStrings);
for(String strString : listStrings)
      System.out.println(strString);I know that I can achieve a similar result by casting the List to an array and then doing a sort and then using addAll() to make it back into a list or I could just use a SortedList of some kind. e.g.
SortedSet<String> setStrings = new TreeSet<String>();I was just windering if there was another method that would be cleaner than this. (A Sorted List of some kind would be very clean unless you wanted to sort the array at a later stage after using it in its unsorted form first, also what if you want duplicates?)

K, I found it in java.utils.Collections
Collections.sort(listStrings);and there is another sort overload which allows you to specify a Comparator.
Perfect.

Similar Messages

  • Calling a Web Service in a SSRS Report - Error Converting String to Generic List of Strings

    Hello,
    I am using SSRS version 2005 and am trying to call a web service to retrieve data for a SSRS report.  I've looked on Google and MSDN for the past 2 days and have exhausted all options.  Here are the details...
    The web service method I am calling accepts 4 parameters...
    Parameter 1 = Generic list of strings
    Parameter 2 = DateTime
    Parameter 3 = Int
    Parameter 4 = Int
    I have created a function (on the CODE tab in report properties) in my report that gets passed a comma delimited string and returns a Generic List of Strings that I use to format Parameter 1.  The code for the function is as follows:
    Public Function GetIDs(ByVal IDList as String) As List(Of String)
       Dim stringArray() = IDList.Split(",")
       Dim genericList As New List(Of String)(stringArray)
       Return genericList
    End Function
    I am passing a string to the function that looks something like this:
    "1,2,3,4"
    When I try to PREVIEW the report, I get an error that reads:
    "There is an error on line 0 of custom code: [BC30002] Type 'List' is not defined"
    I've tried changing the function declaration to pass back a string array:
    Public Function GetIDs(ByVal IDList as String) As String()
        Return IDList.Split(","c)
    End Function
    This returned the error (from the web service): 
    "Error in line 5 position 22.  Expecting state 'Element'.. Encountered 'Text' with name ", namespace"
    I have also tried changing the function declaration to pass back an array: 
    Public Function GetIDs(ByVal IDList as String) As ARRAY
    This also produced the error:
    "Error in line 5 position 22.  Expecting state 'Element'.. Encountered 'Text' with name ", namespace"
    I know that this particular web service method DOES work because it is coded to accept nulls in the first parameter.  So... when I call the method with nulls, it returns a recordset of ALL data (this works fine).  Only when I pass a string to the function (which "filters" the recordset by the ID list), does the error occur.
    Is SRSS limited with respect to VB.NET code so that the List(Of String) statement is not recognized?  Has anyone done this before and if so, how did you convert a comma delimited string to a Generic List of Strings within a function in the SSRS report?
    Any info would be greatly appreciated.
    Thanks!
    Bob

    Hi Bob,
    By default, in custom code, in order to use a variable or function that is not in the "System" namespace, we need to provide the full name.
    In this case, the full name of the "List" is "System.Collections.Generic.List"
    So, to solve the issue, please use the following code:
    Public Function GetIDs(ByVal IDList as String) As System.Collections.Generic.List(Of String)
    Dim stringArray() = IDList.Split(",")
    Dim genericList As New System.Collections.Generic.List(Of String)(stringArray)
    Return genericList
    End Function
    If you have any more questions, please feel free to ask.
    Thanks,
    Jin Chen
    Jin Chen - MSFT

  • Custom Ribbon tab does not show in generic list

    Hi.
    I'm deploying the following definiton on a generic list, but the new custom tab does not show up. Anyone that can see what I have done wrong?
    Thanks!
    <Elements xmlns=”http://schemas.microsoft.com/sharepoint/“>
    <CustomAction
    Id=”Ribbon.MyTab”
    Title=”Adds a new Ribbon tab to Generic List”
    RegistrationType=”List”
    RegistrationId=”100″
    Location=”CommandUI.Ribbon.ListView”
    >
    <CommandUIExtension>
    <CommandUIDefinitions>
    <CommandUIDefinition
    Location=”Ribbon.Tabs._children”>
    <Tab Id=”Ribbon.MyTab” Sequence=”110″ Description=”" Title=”My Tab Name”>
    <Scaling Id=”Ribbon.MyTab.Scaling”>
    <MaxSize
    Id=”Ribbon.MyTab.Scaling.MyGroup.MaxSize”
    Sequence=”15″
    GroupId=”Ribbon.MyTab.MyGroup”
    Size=”LargeMedium”/>
    </Scaling>
    <Groups Id=”Ribbon.MyTab.Groups”>
    <Group
    Id=”Ribbon.MyTab.MyGroup”
    Sequence=”15″
    Description=”"
    Title=”My Group Name”
    Template=”Ribbon.Templates.MyTab.MyGroup.CustomTemplate”>
    <Controls Id=”Ribbon.MyTab.MyGroup.Controls”>
    <Button
    Id=”Ribbon.MyTab.MyGroup.Button”
    Alt=”Ribbon.MyTab.MyGroup.Button”
    Command=”Ribbon.MyTab.MyGroup.Button_CMD”
    Image16by16=”/_layouts/images/siteIcon.png”
    Image32by32=”/_layouts/images/siteIcon.png”
    LabelText=”Button”
    Sequence=”10″
    TemplateAlias=”o1″
    ToolTipTitle=”Button”
    ToolTipDescription=”Shows a dialog” />
    </Controls>
    </Group>
    </Groups>
    </Tab>
    </CommandUIDefinition>
    <CommandUIDefinition
    Location=”Ribbon.Templates._children”>
    <GroupTemplate Id=”Ribbon.Templates.MyTab.MyGroup.CustomTemplate”>
    <Layout Title=”LargeMedium”>
    <OverflowSection Type=”OneRow” TemplateAlias=”o1″ DisplayMode=”Large”/>
    <OverflowSection Type=”ThreeRow” TemplateAlias=”o2″ DisplayMode=”Medium”/>
    </Layout>
    </GroupTemplate>
    </CommandUIDefinition>
    </CommandUIDefinitions>
    <CommandUIHandlers>
    <CommandUIHandler
    Command=”Ribbon.MyTab.MyGroup.Button_CMD”
    CommandAction=”javascript: alert('Hello World');” />
    </CommandUIHandlers>
    </CommandUIExtension>
    </CustomAction>
    </Elements>

    Hello,
    I was able to use your custom ribbon tab XML just fine.  The only thing is, the copy you provided had a bunch of illegal characters embedded in it (like reverse quotes?), I'm not sure if they're showing up in your version of the XML or not.  Anyway,
    after replacing those with straight quotes and fixing some other misc formatting, it worked fine.  I created an empty SharePoint project and added an empty element, then added your XML to the Element.xml file.  In SP, I created a new custom
    list and the "My Tab Name" tab appeared with a button that displayed "Hello World" when I clicked it. So, I recommend checking the formatting of your XML.  Just look for red squiggles in the editor and fix them.
    Regards,
    - Kemp Brown [MSFT]

  • Sorting singly linked list with minimum time complexity

    Hi ...
    anyone could tell me how can i sort singly linked list with minimum time complexity .... ????
    Regards...

    By MergeSort or QuickSort O(n log n). But then you
    have to first extract the objects in the list,sort
    them, then rebuild the list. But it will still bealot
    faster than by keeping the list linked.Technically, I believe insertion sort is marginally
    faster for small n ( <20 or so).Woohoo! So for 20 out of the possible 2147483648 array
    sizes Insetion is faster!
    Unfortunately, checking for that case probably wastes
    all the time you get from using the faster sort...
    That would depend on the actual distribution off array sizes. So it's an engineering decision.
    Sylvia.

  • Set Time Interval with custom fields in generic list with view(SPViewCollection.SPViewType.Calendar)

    I need to set time interval range with custom date fields in sharepoint view SPViewCollection.SPViewType.Calendar. How to do that?
    My code is this:
    System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
    viewFields.Add("FechaInicio");
    viewFields.Add("FechaFin");
    string query = @"<Query>
    <Where>
    <DateRangesOverlap>
    <FieldRef Name=""FechaInicio"" />
    <FieldRef Name=""FechaFin"" />
    <FieldRef Name=""RecurrenceID"" />
    <Value Type=""DateTime"">
    <Week />
    </Value>
    </DateRangesOverlap>
    </Where>
    </Query>";
    SPView newView = reserva.Views.Add("CalendarView", viewFields, query, 0, true, true, SPViewCollection.SPViewType.Calendar, false);
    "FechaInicio" and "FechaFinal" ara datetime fields in my generic list.
    Thanks.

    Hi,
    According to your post, my understanding is that you want to see the calendar view begin and end time for the time interval.
    We can use the SharePoint Manager to view the internal name for the begin and end time for the time interval.
    Open SharePoint Manager 2013->click your site->click
    Lists->select your list name->click Views->select your calendar view name->click the
    Schema Xml to check the internal name for the time interval begin and end.
    We can download the SharePoint Manager in here:
    http://spm.codeplex.com/
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Can we sort saved report list by name

    Hi,
    I have interactive reports and users can open this interactive report and according to their different requirements they can save this report(as a public) with different names.
    Ex: interactive reports
    Reports(lov) :1.Primary report
    2.xxx test
    3.yyyy
    4.abcd test
    5.zzzz test
    Can we sort saved report list by name?
    Could you please guide me to achieve this requirement.
    Thanks in advance.
    Regards
    Narender B

    Narender wrote:
    Hi,
    I have interactive reports and users can open this interactive report and according to their different requirements they can save this report(as a public) with different names.
    Ex: interactive reports
    Reports(lov) :1.Primary report
    2.xxx test
    3.yyyy
    4.abcd test
    5.zzzz test
    Can we sort saved report list by name?
    Could you please guide me to achieve this requirement.It's a lot easier to do so if the following information is provided (as has been repeatedly pointed out to you):
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    Sorting of the saved report list by report name was introduced in APEX 4.1.

  • Cannot implicitly convert type 'Microsoft.SharePoint.SPListItemCollection' to 'System.Collections.Generic.List T '_

    Hi
    I want use SPListItemCollection' to 'System.Collections.Generic.List<T>'.
    How to achieve this.
    Thanks,
    Siva.

    Hi Siva,
    This is how I code it for looping all SPListItem in the SPListItemCollection using Generic List<T>
    public IEnumerable GetEnumerator()
    using (SPSite site = new SPSite(SPContext.Current.Site.Url))
    using (SPWeb web = site.OpenWeb())
    var list = web.Lists["Friends"];
    var query = new SPQuery();
    query.Query = "<FieldRef Name='ID'/>";
    IEnumerable items = list.GetItems(query);
    return items;
    Then calling the method would be
    var items = GetEnumerator();
    foreach(SPListItem item in items)
    Response.Write(item["FirstName"]);
    Murugesa Pandian| MCPD | MCTS |SharePoint 2010

  • Contact sorting broken in "Lists" print option?

    Wanted to print a simple contact list out of Address Book / er um... "Contacts".
    If i select "Mailing Lables", "Envelopes", or "Pocket Address Book"  everything seems to work as it should.
    However, if i select "Lists" the sort-order of list is completely messed-up.  I can't even make a guess at what criteria it might be trying to sort by, but it certianly isn't the names.
    Replicated the issue on my iMac running Mountain Lion as well.
    Anybody else seeing the same thing?
    ML bug or just something whacked w/ my contacts?

    Hi Peter,
    I can now rest assured that you feel my pain about being in so much pain, as its so painful being in this state of pain it must be a pain just reading this as it is sure is painful me writing it, pain pain pain.
    Yours,
    Pain
    PS
    pain |pān|
    noun
    1 physical suffering or discomfort caused by illness or injury: she's in great pain | those who suffer from back pain | chest pains.
    • mental suffering or distress: the pain of loss.
    • (also pain in the neck or vulgar slang pain in the *** ) [ in sing. ] informal an annoying or tedious person or thing: she's a pain.
    2 (pains) careful effort; great care or trouble: she took pains to see that everyone ate well | he is at pains to point out that he isn't like that.
    verb [ with obj. ]
    cause mental or physical pain to: it pains me to say this | her legs had been paining her.
    • [ no obj. ] (of a part of the body) hurt: sometimes my right hand would pain.
    PHRASES
    for one's pains informal as an unfairly bad return for efforts or trouble: he was sued for his pains.
    no pain, no gain suffering is necessary in order to achieve something.
    [originally used as a slogan in fitness classes.]
    on (or under ) pain of the penalty for disobedience or shortcoming being: all persons are commanded to keep silent on pain of imprisonment.
    ORIGIN Middle English (in the sense ‘suffering inflicted as punishment for an offense’): from Old French peine, from Latin poena ‘penalty,’ later ‘pain.’

  • Systems.Collections.Generic.List T Requires 1 Type of Argument?

    I am having troubles with my code. I am trying to start a list entitles "studentList" and it is supposed to allow the user to enter in a list of student names and their ages. 
    Below is my code and this is a windows Forms:
    <code>
    List<Student> studentList = new List();
            private void btnAddStudent_Click(object sender, EventArgs e)
            private void btnShowStudents_Click(object sender, EventArgs e)
                List<Student> sortedList = studentList.OrderBy(o => o.LastName).
                                                  ThenBy(o => o.FirstName).ToList();
                String outputStr = "";
                foreach (Student s in sortedList)
                    if (outputStr != "")
                        outputStr += "\n--------------\n";
                    outputStr += s.ToString();
                if (outputStr == "")
                    outputStr = "No Student Records Yet!";
                MessageBox.Show(outputStr);
    </code>
    I have other code as well but this is the problem area. I am getting a Systems.Collections.Generic.List<T> Requires 1 Type of Argument error on this line of code: List<Student> studentList = new List(); and I cannot figure out why.
    If I change it to List<string>studentList = new List<string>(); I get an error later on in the code.
    I'm sorry if this is confusing but this is a really complex assignment that I've been working on for hours and I'm completely frustrated because I'm so close to finishing.
    Any help would be appreciated!
    Thanks :)

    I am having troubles with my code.
    If you post this to a C# and not to a VB forum, you'll have the chance all your troubles are gone. :)
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral
    Armin

  • How to sort Reminders (in List mode)?

    How do I sort Reminders (in List mode) in chronological sequence according to due date?
    It works automatically in iCloud via web browser, but apparently not in the iPhone Reminders app. Please help. Thank you!

    Apparently, Apple thinks you don't need to sort them. They will thus appear in the order you create them. This is also bugging me though, along with all of the other problems with this app. (not possible to set due date on iPhone)
    Oh, if you want to help, submit this "feature" to Apple at this page:
    http://www.apple.com/feedback/iphone.html

  • Error when getting only generic lists in a web

    Error : Cannot read property 'ListTemplateType' of null 
    function genlistdisplay(){
    var lists = web.get_lists();
    //context.load(lists, 'ListTemplateType');
    context.load(lists);
    context.executeQueryAsync(onGetSuccess, onGetFailed);
    function onGetSuccess(sender,args){
    $.each(lists, function(i, list){
    alert("In LOOP");
    $('#listsSelect').empty();
    var listEnumerator = lists.getEnumerator();
    while(listEnumerator.moveNext()){
    var currlist =listEnumerator.get_current();
    var lsttype = currlist.get_baseType();
    alert("listtemplate- Before condition");
    if(list.ListTemplateType == SP.ListTemplateType.genericList){
    alert("listtemplate- IN the condition");
    var selectoption = document.createElement("option");
    selectoption.value = listEnumerator.get_current().get_title();
    selectoption.innerHTML = listEnumerator.get_current().get_title();
    $('#listsSelect').add(selectoption);
    $('#listsSelect').append(selectoption);
    alert("Success");
    alert("After Generic list");
    Ram

    You would need to compare List.BaseTemplate.
    if (lsttype === SP.BaseType.genericList)
    kashif

  • How can I sort the delegates list?

    I am using iCal in an office situation and am managing a large number (15) of delegates (they all have their own calender).
    I can sort the delegates list via Preferences, Accounts, Delegation and then add the delegates I need in the order that I prefer.
    But I am looking for a more easier way to sort this list.
    Who can help me with this?

    Hi Katherine,
    You have to specify the order manually I'm afraid.
    Regards,
    Jamie

  • Sort the themes list?

    Hello!
    I can't figure out how Keynote sorts its themes list. There are a few that I use a lot, and others that I don't use much at all. Unfortunately, a couple that I want regularly are at the bottom of my 60+ themes list... and are a drag to use when I use multiple variants of a theme in a presentation to represent different concepts/ideas. Is there an easy way to reorder the list?

    Some versions of Keynote alphabetize at the folder level first, then the theme level (you can have folders in your themes folder), others just read every theme and then put them in order. If you want things to be at the top, you can go into the themes folder and put spaces or other characters at the front of the theme name. Keep in mind that the Apple themes will ALWAYS be at the top because they're inside the Keynote application, not in the themes folder.

  • How can I sort the target list in debug form.

    If I want to select a procedure/function to debug it is very hard to find it if the package contains a lot of procedures. How can I sort the target list. I did not find anything in the preferences. Thanks.

    Sorry, can't be done. You can request this at the SQL Developer Exchange though, so other users can vote and add weight for possible future implementation.
    My suggestion (if you decide to request it): base the order in the dialog on the order inside the navigator tree (location in the source by default, but possible by name or type/name - see tree's context menu).
    Regards,
    K.

  • Reference to "System.Collection.Generic.List"

    Encountered a problem when making a .NET method call:
    MT8855.StatusCode SetBluetoothProfile(
    MT8855.BluetoothProfileConfiguration newProfileConfiguration,
    ref List<MT8855.InvalidSettingInfo> invalidList
    Parameters
    newProfileConfiguration
    Type: Anritsu.MMD.MT8855x.TestSet.MT8855.BluetoothProfileConfiguration
    The structure containing the new settings.
    invalidList
    Type: System.Collections.Generic.List (Of <MT8855.InvalidSettingInfo>)
    A list to hold information about any settings that are invalid.
    Return Value
    Status code indicating the success or otherwise of the call.
    What should I do in TestStand to pass the reference of the list? 

    Hi,
    Just also visit this thread
    http://forums.ni.com/t5/NI-TestStand/How-to-iterat​e-though-a-net-dictionary/td-p/1232557
    Regards
    juergen
    =s=i=g=n=a=t=u=r=e= Click on the Star and see what happens :-) =s=i=g=n=a=t=u=r=e=

Maybe you are looking for

  • How to delete a MOV file off of my iPad

    I just bought a Nikon S8100 camera, it can shoot video as well. I shot a couple of test videos, and left it in 1080p mode. I used my camera kit to connect it directly to my iPad, and uploaded the pictures I had taken, and the two videos. They all loa

  • Tried to restore and phone has frozen on white apple screen

    i plugged my partners phone in to update, it said that there was an error and i should restore it, i did that and it said there was an error nd ejected the phone i plugged it back in twice and then it just froze on the black screen with the white app

  • Count of non-empty rows of a table

    How to I get the number of non-empty rows of a table ? Thanks

  • Any one music messed up after the upgrade to iso5?

    After the upgrade to ios5 many of the songs that use to play on my iPad no longer work. Does any one know why this would happen?

  • New app idea - blog title optimizer

    I just came across a Wordpress app called Headlines. I'd love to see this as a BC app! http://kingsumo.com/apps/headlines/ I'm not a dev, but thought I'd share this if anyone wants to take a stab at it.