Results 1 to 6 of 6

Thread: ArrayList - Sort by Index

  1. #1
    Join Date
    Dec 2009
    Posts
    263

    ArrayList - Sort by Index

    Hello,
    I am trying to do, I type my objects Concordance, which are mainly composed of three <String> ArrayList (indexTete is not relevant here).
    Code:
    Public class Concordance implements Similar{
        
        / / Attribute
        
        private Final ArrayList <String> pivot ctxg, ctxd;
        private Final int ind;
        
        / / Constructors
        // ...
    In the case of this list correspondences are constructed so that, everywhere, to pivot the same long p, ctxG the same length and g ctxD the same length d, for I must argue against whatever the values of p, g and d. I am trying here to sort the array list by the index. But i am un successful, if you have any idea about it, then I am interested.

  2. #2
    Join Date
    Nov 2009
    Posts
    335

    Re: ArrayList - Sort by Index

    Hello.
    For the parameter passing, use the constructor .
    Example:
    Code:
    Public class pvcom <Concordance>{
      private int i;
      Public pvcom(int i){
        this.i = I;
      }
     
      Public int compares(Concordance arg0, arg1 Concordance){
        return arg0.get(i).compareTo(arg1.get(i));
      }
    }
    Hope you problem is solved and you are understanding he things.

  3. #3
    Join Date
    Dec 2009
    Posts
    263

    Re: ArrayList - Sort by Index

    Hello,
    I have tried a bit and here is my updated and modified code, just check it out and if you find any wrong thing in the code then please guide me with the correct.
    Code:
    Public class pvcom <Concordance>{
        
        / / Attribute
        private int idx;
        
        / / Constructor
        Public pvcom(int i){
            this.idx = I;
        }
        
        / / Method
        Public int compares(Conc1 Concordance, Concordance conc2){
            return conc1.getPivot().get(idx).compareTo(conc2.getPivot().get(idx));
        }
        
    }

  4. #4
    Join Date
    Nov 2009
    Posts
    347

    Re: ArrayList - Sort by Index

    Hello,
    The problem is that the method compares receives 2 Objects and not 2 and Concordances I think it comes from the statement of KWIC or instantiation of its components. Would you STP gives us a snippet (especially not your whole program : It scares away people from dozens of lines of code ...). So a snippet that includes the declaration of KWIC and its initialization. For this story locally, I'm not sure I follow you. More details are welcome.

  5. #5
    Join Date
    Dec 2009
    Posts
    263

    Re: ArrayList - Sort by Index

    Hello,
    I'll try to explain everything, putting only what is necessary.
    Regarding the statement of KWIC and initialization:
    Code:
    ArrayList <Integer> index = new ArrayList();
    / / Index ... I filled ...
    ArrayList <Concordance> KWIC = new ArrayList(index.size());
    for(int i = 0; I <index.size(); I + +){
         KWIC.add(new Concordance(this.items, Index.get(i), Q.size(), G, d));
    }
    Once I did that, I no longer touches KWIC (except for sorting). I have not touched PivotComparator <Concordance> since my last post (I had copied my code).

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: ArrayList - Sort by Index

    Hello,
    Code:
    ArrayList <Concordance> KWIC = new ArrayList (index.size ());
    I would say about this is
    Code:
    List KWIC <Concordance> = new ArrayList <Concordance>
    (index.size ());
    Always trying to use interface for reporting: List, Set, Map, etc.. and selected implementation when instantiation. Another thing, If you use generics in Java 5.0, do it in the declaration and the instantiation.
    Code:
    List <Type> x = new ArrayList <Type>();
    For local history, I confess that I do not know. But I think it's in the comparison of String as it comes.

Similar Threads

  1. Replies: 3
    Last Post: 04-01-2011, 01:25 AM
  2. Does Google decides which content to index & what not to index?
    By Uddhav in forum Technology & Internet
    Replies: 5
    Last Post: 04-03-2010, 07:37 PM
  3. How to sort items of an ArrayList in java?
    By hounds in forum Software Development
    Replies: 4
    Last Post: 06-02-2010, 07:46 PM
  4. How to use Bubble sort in C# to sort parallel arraylists
    By Ground 0 in forum Software Development
    Replies: 3
    Last Post: 03-08-2009, 12:12 PM
  5. Inserting an index entry into index 0 of file 25
    By Dharmesh Arora in forum Operating Systems
    Replies: 3
    Last Post: 16-07-2009, 10:10 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,727,109,873.03567 seconds with 17 queries