aspose file tools*
The moose likes Java in General and the fly likes Merge two arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Merge two arrays " Watch "Merge two arrays " New topic
Author

Merge two arrays

Hui Zhao
Ranch Hand

Joined: Jul 09, 2007
Posts: 116
Suppose a1 and a2 are two dimensional arrays

My goal is to append the second row according to the first row's matchness.
Finally if
merge the first row of a1 and a2 should get


I have three days but no achievement.
Here is the code.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Consider how you could use a Map (for your purposes, a java.util.LinkedHashMap would be a wise choice) to store the relationship between the first and second strings. Since a Map automatically eliminates duplicate keys, and since LinkedHashMap stores the keys in insertion order, it would do virtually all of the work for you. You'd just add all the pairs, allocate new arrays the same size as the map, then iterate over the map and populate the two arrays.


[Jess in Action][AskingGoodQuestions]
Hui Zhao
Ranch Hand

Joined: Jul 09, 2007
Posts: 116
I am not familiar with using Map skills.
Would you please provide me a piece of code?

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Merge two arrays