0

I couldn't find a better title than that so pardon me for any kind of confusion.

I want to combine two hashmap into one hashmap.I am actually using hashmaps to contain the datas of table where key=coloumName and value= coloumValues. My code looks something like

HashMap<String, ArrayList> FTMap = table1.getColumn().getColumnValues()
HashMap<String, ArrayList> STMap = table2.getColumn().getColumnValues()

HashMap<String, ArrayList> FinalTableMap = new HashMap()

FinalTableMap.putAll(FTMap)
FinalTableMap.putAll(STMap)

I don't have any problem with column names but the order of coloumvalues are not working after the combining. Since i am using arraylist,i am trying to compare two arraylist and put it in a final arraylist which can be used as the value of the final hashmap.I need some advice or suggestion for this matching between two arraylist.

vanje
  • 10,180
  • 2
  • 31
  • 47
  • My code contains some other things(which is working) So I didnt submit any codes here.If my question was not clear enough please let me know. – user1464906 Jun 18 '12 at 22:15
  • 1
    some examples of hashmap content and expected output would be helpful. – yankee Jun 18 '12 at 22:17
  • yankee -lets assume the contents of hashmap is like – user1464906 Jun 19 '12 at 11:38
  • FTMap- Name id Gender A 1 Male B 2 Female C 3 Male STMap Name Gender Country X Male Australia A Male Germany B Female India my output is like Name id Gender Country A 1 Male Australia B 2 Female Germany C 3 Male India X Male what i want is Name Id Gender Country A 1 Male Germany B 2 Female India C 3 Male Null X null Male Australia @yankee thanks – user1464906 Jun 19 '12 at 11:54
  • @user1464906 Unreadable. Please edit that into your post where you can format it properly. – user207421 Jun 25 '12 at 03:27
  • What does 'the order of column values not working' mean? – user207421 Jun 25 '12 at 03:28

1 Answers1

1

After you have used addAll to combine your lists, you can use Collections.sort(List, Comparator) to sort your ArrayList. In your Comparator's compare function, you will compare the two objects using the values you wish to sort by (you mentioned serial id?).

See Sort ArrayList of custom Objects by property for a brief example.

Community
  • 1
  • 1
cklab
  • 3,761
  • 20
  • 29