不同类型数据的数据格式对象、数组、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,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]123[q,w,e][q,e,q1,w1,e1,r1,t1]{{3=3}=fghfg,{2=2}=hfdg,{1=1}=asda}{"id":0,"password":"123456","quanxian":1,"username":"zhangsan"}

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...