-1

I have below code

@Embedabble
public class key {
    @Id
    private String id;
    @Id
    private String Name;
    //getters setters
}

@Entity
public class Information {
    @EmbeddedId
    private Key key;
    //Getters and setters

}

public class Service {

    @Autowired
    private Information information;

    public inforamtionResponse service() {

        List<Information> infot = repo.getInformation();

    }

}

I want to store infot in map form such as id as key and name as value. using java 8 stream how can I do that?

I tired using java8 stream but unable fetch object from object.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
Niks
  • 1
  • 2
  • 1
    Please edit your question and add your code. It's not clear what you mean by *[..]fetch object from object*. Add your code and explain your problem more clearly – Thiyagu Jan 02 '23 at 08:25
  • 2
    Can you please show what you have tried? – dan1st Jan 02 '23 at 08:29

1 Answers1

0

using by Collectors.toMap()

List<Information> infot = repo.getInformation();
Map<String, String> map = infot.stream().collect(Collectors.toMap(Information::getId, Information::getName));