Java list into map

Source: Internet
Author: User

Table structure: tmdictionary

CREATE TABLE ts_data_dic
(
  ID serial not NULL,
  value_name character varying () is not NULL,-the description of the value corresponds to the
  valu E_code character varying (20),--the corresponding code value
  type_code character varying (a), type_name character varying
  (30),
  comments character varying (m),
  create_by Integer,
  create_date timestamp, without time zone,
  last_ Update_by Integer,
  last_update_date timestamp without time zone,
  row_version numeric (14,0) not NULL DEFAULT 0,
  IsValid Numeric (1,0) not NULL default 1,
  parent_id Integer,
  editable integer NOT NULL default 1,
  sor t integer,
  CONSTRAINT pk_ts_data_dic PRIMARY key (ID),
  CONSTRAINT fk_ts_data_dic FOREIGN key (parent_id)
      REFERENCES ts_data_dic (ID) MATCH
      simple On UPDATE RESTRICT on DELETE RESTRICT
)


The implementation returns a map<valuecode,tmdictionary> based on the incoming TypeCode

  Public map<string, Tmdictionary> findbytypecode (string typecode) {
    	string hql= ' SELECT DISTINCT TM from Tmdictionary TM LEFT Join Tm.parent parent where  tm.isvalid=:isvalid and Tm.typecode=:code ";
    	map<string,object> params = new hashmap<string, object> ();
    	Params.put ("IsValid", 1);
    	Params.put ("code", TypeCode);
		List<tmdictionary> list= (list<tmdictionary>) dictionarydao.query (HQL, params);
        Map<string,tmdictionary> map=new hashmap<string, tmdictionary> ();
        For (tmdictionary  dic:list) {
        	if (dic==null) {
        		continue;
        	}
        	Map.put (Dic.getvaluecode (), DIC);
        }
        return map;
    }


Test code:

@Test public
	void Findbytypecode () {
		map<string, tmdictionary> map= ditionaryservice.findbytypecode (" Lockedname ");
		For (entry<string, tmdictionary> entry:map.entrySet ()) {
			System.out.println (Entry.getkey () + ":" + Entry.getvalue ());
		}
		
	

Original link:

List:

School Number
Name
Class
1
Songjl1
Class 1, Level 01.
2
Songjl2
Class 1, Level 02.
3
Songjl3
Class 1, Level 03.
Convert to map

list<student> list = new arraylist<student> ();
  Map<integer, student> map = new Hashmap<integer, student> ();
  for (Student stu:list) {
   if (stu==null) {
    continue;
   }
   The student is a JavaBean object. Data number, name, class
   //Number as key.
   Map.put (Stu.getstuno (), Stu);
  }



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.