0
How to make "pair" of more than 2 elements then sort by first element in java?
Paring in java
6 Answers
+ 1
Hello R_C
Can you add an example?
If you have only a pair and if you are using numbers you can use < and >.
for example 4, 3
4 > 3 -> swap them to get 3, 4
+ 1
Can you please make your question more descriptive? Also, try to include a program of your own, as currently this seems like homework.
+ 1
Hello R_C
My idea is to store the name and the index in a hashmap.
a has index 0, 4 belongs to a and has index 0 and 25000 belongs to a and has index 0.
a = 0
c = 1
g = 2
After storing the index you can do what ever you want with the names. And you don't need to do anything with the other arrays.
Here is a small code example:
https://code.sololearn.com/cUnqcl3V7DoQ/?ref=app
+ 1
@Denise RoĂberg
Got it. Thank you
+ 1
Denise RoĂberg
What if two or more names are same
0
Denise RoĂberg
if there are three arrays
Name={"a", "c", "g"}
ID={4,1,9}
Salary={25000,42000,11000}
i.e; a person name "a" having ID 4 and salary 25000
I want to sort the combined array i ascending according to ID. i.e;
Name ={"c", "a", "g"}
ID = {1,4,9}
Salary = {42000,25000,11000}
and show the answer as
c 1 42000
a 4 25000
g 9 11000