java中如何返回多个list
for(NewMapTabe:list1){//查询上游监测点的经纬度Stringsql2="selectLON,LATfromjnc_baiduwhereID='"+e...
for(NewMapTab e:list1){
//查询上游监测点的经纬度
String sql2 = "select LON,LAT from jnc_baidu where ID = '"+e.getID()+"'";
pstmt2 = conn.prepareStatement(sql2);
rs2 = pstmt2.executeQuery();
while(rs2.next()){
NewMapTab p = new NewMapTab();
p.setLAT(rs2.getFloat(1));
p.setLON(rs2.getFloat(2));
pointlist1.add(p);
}
}
for(NewMapTab e:list2){ //查询下游监测点的经纬度
String sql3 = "select LON,LAT from jnc_baidu where ID = '"+e.getID()+"'";
pstmt3 = conn.prepareStatement(sql3);
rs3 = pstmt3.executeQuery();
while(rs3.next()){
NewMapTab po = new NewMapTab();
po.setXlAT(rs3.getFloat(1));
po.setXLON(rs3.getFloat(2));
pointlist2.add(po);}
}
我需要返回pointlist1和pointlist2,该怎么办 展开
//查询上游监测点的经纬度
String sql2 = "select LON,LAT from jnc_baidu where ID = '"+e.getID()+"'";
pstmt2 = conn.prepareStatement(sql2);
rs2 = pstmt2.executeQuery();
while(rs2.next()){
NewMapTab p = new NewMapTab();
p.setLAT(rs2.getFloat(1));
p.setLON(rs2.getFloat(2));
pointlist1.add(p);
}
}
for(NewMapTab e:list2){ //查询下游监测点的经纬度
String sql3 = "select LON,LAT from jnc_baidu where ID = '"+e.getID()+"'";
pstmt3 = conn.prepareStatement(sql3);
rs3 = pstmt3.executeQuery();
while(rs3.next()){
NewMapTab po = new NewMapTab();
po.setXlAT(rs3.getFloat(1));
po.setXLON(rs3.getFloat(2));
pointlist2.add(po);}
}
我需要返回pointlist1和pointlist2,该怎么办 展开
4个回答
展开全部
方法一、将多个List封装到一个JavaBean内:
private static void show1() {
StringEQTest.ListArr listArr = new StringEQTest.ListArr();
List<String> names = listArr.names;
for (int i = 0; i < names.size(); i++) {
System.out.println(names.get(i));
}
List<Integer> ages = listArr.ages;
for (int i = 0; i < ages.size(); i++) {
System.out.println(ages.get(i));
}
}
public static class ListArr {
List<String> names = new ArrayList<String>();
List<Integer> ages = new ArrayList<Integer>();
public ListArr() {
names.add("names1");
names.add("names2");
names.add("names3");
ages.add(50);
ages.add(40);
ages.add(30);
ages.add(88);
}
public List<String> getNames() {
return names;
}
public void setNames(List<String> names) {
this.names = names;
}
public List<Integer> getAges() {
return ages;
}
public void setAges(List<Integer> ages) {
this.ages = ages;
}
}
结果:
names1
names2
names3
50
40
30
88
-------------------------------------------------------------------------------
方法二、将List包装到Map集合内,取出的时候需要进行类型转换
private static void show2() {
Map<String, Object> lists = getLists();
List<String> names = (List<String>) lists.get("names");
for (int i = 0; i < names.size(); i++) {
System.out.println(names.get(i));
}
List<Integer> ages = (List<Integer>) lists.get("ages");
for (int i = 0; i < ages.size(); i++) {
System.out.println(ages.get(i));
}
}
public static Map<String, Object> getLists() {
List<String> names = new ArrayList<String>();
List<Integer> ages = new ArrayList<Integer>();
names.add("names1");
names.add("names2");
names.add("names3");
ages.add(50);
ages.add(40);
ages.add(30);
ages.add(88);
Map<String, Object> map = new HashMap<String, Object>();
map.put("names", names);
map.put("ages", ages);
return map;
}
结果:
names1
names2
names3
50
40
30
88
private static void show1() {
StringEQTest.ListArr listArr = new StringEQTest.ListArr();
List<String> names = listArr.names;
for (int i = 0; i < names.size(); i++) {
System.out.println(names.get(i));
}
List<Integer> ages = listArr.ages;
for (int i = 0; i < ages.size(); i++) {
System.out.println(ages.get(i));
}
}
public static class ListArr {
List<String> names = new ArrayList<String>();
List<Integer> ages = new ArrayList<Integer>();
public ListArr() {
names.add("names1");
names.add("names2");
names.add("names3");
ages.add(50);
ages.add(40);
ages.add(30);
ages.add(88);
}
public List<String> getNames() {
return names;
}
public void setNames(List<String> names) {
this.names = names;
}
public List<Integer> getAges() {
return ages;
}
public void setAges(List<Integer> ages) {
this.ages = ages;
}
}
结果:
names1
names2
names3
50
40
30
88
-------------------------------------------------------------------------------
方法二、将List包装到Map集合内,取出的时候需要进行类型转换
private static void show2() {
Map<String, Object> lists = getLists();
List<String> names = (List<String>) lists.get("names");
for (int i = 0; i < names.size(); i++) {
System.out.println(names.get(i));
}
List<Integer> ages = (List<Integer>) lists.get("ages");
for (int i = 0; i < ages.size(); i++) {
System.out.println(ages.get(i));
}
}
public static Map<String, Object> getLists() {
List<String> names = new ArrayList<String>();
List<Integer> ages = new ArrayList<Integer>();
names.add("names1");
names.add("names2");
names.add("names3");
ages.add(50);
ages.add(40);
ages.add(30);
ages.add(88);
Map<String, Object> map = new HashMap<String, Object>();
map.put("names", names);
map.put("ages", ages);
return map;
}
结果:
names1
names2
names3
50
40
30
88
展开全部
List<List,List>
你返回list,里面有两个list就能搞定
你返回list,里面有两个list就能搞定
追问
for(int i=0;i<id1.size();i++){
System.out.println(id1.get(i).getLON());
}
我这样取出来,结果中除了所需的LON值外还有很多0.0这种值
追答
那你的数据,我怎么知道,估计是double
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
// 定义一个list.存放两个变量,然后返回
List<T> list = new ArrayList<T>();
list.add(pointlist1);
list.add(pointlist2);
List<T> list = new ArrayList<T>();
list.add(pointlist1);
list.add(pointlist2);
追问
如何合理的把每个值取出来?
追答
list.get(0) ===> 可以取出pointlist1
list.get(1) ===> 可以取出pointlist2
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
新建一个链表,把这两个存里边试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询