如何把ArrayList的数据从一类迁移到另一个类 [英] How to migrate the data of my arraylist from one class to another class
问题描述
所以,我有我的 ERDBUILDER.java
类是拉丝面板,让我画存储一个ArrayList 连接<内部形状/ code>。我也喜欢基于ArrayList中从另一个类SQL.java访问此ArrayList和创建我的SQL语句。我已经试过codeS后面,但我不知道主类应该如何。我试图把
新的SQL();
主类,但它打开另一个 ERDBUILDER.java
类和这不正是我想要做的事。
那么,如何可以运行此,主类应该如何?
EDITED
任何人都可以帮忙吗?
包项目;\r
进口java.awt.Shape中;\r
进口的java.util.ArrayList;\r
进口project.ERDBUILDER.DrawingBoard.Attribute;\r
进口project.ERDBUILDER.DrawingBoard.Connection;\r
进口project.ERDBUILDER.DrawingBoard.Connection2;\r
进口project.ERDBUILDER.DrawingBoard.NamedShape;\r
\r
\r
公共类SQL {\r
\r
公共静态无效的主要(字符串ARGS []){\r
ArrayList的&LT;连接GT&; CON =新的ArrayList&LT;&GT;();\r
\r
对于(int类型的= 0; A&LT; con.size(); A ++){\r
NamedShape F = con.get(一).getNamedShape1();\r
属性G = con.get(一).getNamedShape2();\r
串I = f.getName();\r
串J = g.getName();\r
\r
形状Y = f.getShape();\r
形状Y1 = g.getShape();\r
的System.out.println第(i +和+ J +链接);\r
\r
\r
\r
\r
}\r
}\r
\r
}
\r
要在其中创建SQL语句和连接的ArrayList传递给类,创建类的实例。
列表&LT;连接GT&; CON =新的ArrayList&LT;&GT;();
ERDBuilder X =新ERDBuilder(CON);
您ERDBuilder构造可以采取一个List对象,并用它来建立一个SQL语句。或者,你甚至可以做到这一点的ERDBuilder的方法。这是你的选择。
ERDBuilder X =新ERDBuilder();
清单&LT;连接GT&; CON =新的ArrayList&LT;&GT;();
x.buildSql(CON);
如果您想从主做它,那么你必须声明的列表作为类级别的变量,你已经在做ERDBuilder以同样的方式。
So i have my an ERDBUILDER.java
class is a drawing panel which allows me to draw shapes that are stored inside an arraylist Connection
. I would liked to access this arraylist from another class SQL.java and create my sql statement based on the arraylist. I've tried the codes that follows but i don't know how the main class should be. I've tried to put new SQL();
in the main class but it's opening another ERDBUILDER.java
class and that not what i want it to do.
So how can i run this, how the main class should be?
EDITED Anyone can help?
package project;
import java.awt.Shape;
import java.util.ArrayList;
import project.ERDBUILDER.DrawingBoard.Attribute;
import project.ERDBUILDER.DrawingBoard.Connection;
import project.ERDBUILDER.DrawingBoard.Connection2;
import project.ERDBUILDER.DrawingBoard.NamedShape;
public class SQL {
public static void main(String args[]){
ArrayList<Connection> con = new ArrayList<>();
for (int a = 0; a < con.size(); a++) {
NamedShape f = con.get(a).getNamedShape1();
Attribute g = con.get(a).getNamedShape2();
String i = f.getName();
String j = g.getName();
Shape y = f.getShape();
Shape y1 = g.getShape();
System.out.println(i + " AND " + j + " are linked");
}
}
}
Create an instance of the class where you want to create the SQL statement and pass the Connection ArrayList to that class.
List<Connection> con = new ArrayList<>();
ERDBuilder x = new ERDBuilder(con);
Your ERDBuilder constructor can take a List object and use it to build a SQL statement. Or you can even do this in a method of ERDBuilder. That is your choice.
ERDBuilder x = new ERDBuilder();
List<Connection> con = new ArrayList<>();
x.buildSql(con);
If you want to do it from main then you have to declare the List as a Class level variable, the same way you have done with the ERDBuilder.
这篇关于如何把ArrayList的数据从一类迁移到另一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!