Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 11-02-2010
Member
 
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.
Reply With Quote
  #2  
Old 11-02-2010
Member
 
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.
Reply With Quote
  #3  
Old 11-02-2010
Member
 
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));
    }
    
}
Reply With Quote
  #4  
Old 11-02-2010
Member
 
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.
Reply With Quote
  #5  
Old 11-02-2010
Member
 
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).
Reply With Quote
  #6  
Old 11-02-2010
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "ArrayList - Sort by Index"
Thread Thread Starter Forum Replies Last Post
What is the difference between binary tree sort and heap sort in data structure sRIPRIYA Software Development 3 04-01-2011 01:25 AM
Does Google decides which content to index & what not to index? Uddhav Technology & Internet 5 04-03-2010 07:37 PM
How to sort items of an ArrayList in java? hounds Software Development 4 06-02-2010 07:46 PM
How to use Bubble sort in C# to sort parallel arraylists Ground 0 Software Development 3 03-08-2009 12:12 PM
Inserting an index entry into index 0 of file 25 Dharmesh Arora Operating Systems 3 16-07-2009 10:10 AM


All times are GMT +5.5. The time now is 08:03 PM.