• 不同类型数据的数据格式(对象、数组、list容器、map容器、list内嵌list容器、map内嵌map容器、json)


    package cn.itcast.jk;

    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    import com.alibaba.fastjson.JSONArray;


    public class Test
    {
    public static void main(String[] args)
    {
    User user = new User();
    user.setId(0);
    user.setPassword("123456");
    user.setQuanxian(1);
    user.setUsername("zhangsan");
    System.out.println(user);

    String[] a = {"1","2","3"};
    for (String string : a)
    {
    System.out.println(string);
    }

    List list = new ArrayList<String>();
    list.add("q");
    list.add("w");
    list.add("e");
    System.out.println(list);

    List list2 = new ArrayList<String>();
    list2.add("q1");
    list2.add("w1");
    list2.add("e1");
    list2.add("r1");
    list2.add("t1");
    // System.out.println(list2);

    List list3 = new ArrayList();
    list3.addAll(list);
    list3.addAll(list2);
    System.out.println(list3);

    HashMap<Map<String,String>,Object> map = new HashMap<Map<String,String>,Object>();
    Map<String, String> map1 = new HashMap<String,String>();
    map1.put("1", "1");
    Map<String, String> map2 = new HashMap<String,String>();
    map2.put("2", "2");
    Map<String, String> map3= new HashMap<String,String>();
    map3.put("3", "3");
    map.put(map1, "asda");
    map.put(map2, "hfdg");
    map.put(map3, "fghfg");
    System.out.println(map);

    String objJson = JSONArray.toJSONString(user);
    System.out.println(objJson);
    }
    }

    -----------------------------------------------------------------------------------------------

    package cn.itcast.jk;

    /**
    * User entity. @author MyEclipse Persistence Tools
    */

    public class User implements java.io.Serializable {


    // Fields

    private Integer id;
    private String username;
    private String password;
    private Integer quanxian;

    // Constructors

    /** default constructor */
    public User() {
    }


    /** full constructor */
    public User(String username, String password) {
    this.username = username;
    this.password = password;
    }


    // Property accessors

    public Integer getId() {
    return this.id;
    }

    public void setId(Integer id) {
    this.id = id;
    }

    public String getUsername() {
    return this.username;
    }

    public void setUsername(String username) {
    this.username = username;
    }

    public String getPassword() {
    return this.password;
    }

    public void setPassword(String password) {
    this.password = password;
    }

    public Integer getQuanxian()
    {
    return quanxian;
    }

    public void setQuanxian(Integer quanxian)
    {
    this.quanxian = quanxian;
    }


    @Override
    public String toString()
    {
    return "User [id=" + id + ", username=" + username + ", password=" + password + ", quanxian=" + quanxian + "]";
    }

    }

    ----------------------------------------------------------------打印结果-------------------------------------------------------------------------------------

    User [id=0, username=zhangsan, password=123456, quanxian=1]
    1
    2
    3
    [q, w, e]
    [q, w, e, q1, w1, e1, r1, t1]
    {{3=3}=fghfg, {2=2}=hfdg, {1=1}=asda}
    {"id":0,"password":"123456","quanxian":1,"username":"zhangsan"}

  • 相关阅读:
    数据结构与算法(3-4)--矩阵的压缩存储
    数据结构与算法(3-3)--队列的应用
    数据结构与算法(3-2)--栈的应用
    数据结构与算法(3-1)--栈和队列
    数据结构与算法(2)--线性表(数组和链表)
    数据结构与算法(1)--时间及空间复杂度
    python变量与地址的关系
    python高级(03)--socket编程
    python高级(02)--生成器和迭代器
    python处理http接口请求
  • 原文地址:https://www.cnblogs.com/xyyou/p/11537181.html
Copyright © 2020-2023  润新知