arraylist
how can i implement an arraylist to store integer values and then retrieve them in a new method
and wht are all synatx tht shd i use
how can i implement an arraylist to store integer values and then retrieve them in a new method
and wht are all synatx tht shd i use
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.applet.*;
import java.util.ArrayList;
/*
<applet code="Demo" width=250 height=150>
</applet>
*/
public class Demo extends Applet implements ActionListener{
Label llist[] = new Label[2];
Button blist[] = new Button[2];
static String xx[] = {"one","one1"};
static String yy[] = {"two","two1"};
ArrayList a = new ArrayList();
Button two;
Label one;
public void init()
{
for(int i=0;i<2;i++)
{
one = new Label(xx);
llist=(Label) add(one);
two= new Button(yy);
two.setFont(new Font("SansSerif", Font.BOLD, 18));
blist = (Button) add(two);
two.addActionListener(this);
a.add(20);
}
}
public void actionPerformed(ActionEvent ae)
{
String str = ae.getActionCommand();
if(str.equals("two"))
{
msg = "You pressed two.";
}
repaint();
}
public void paint(Graphics g)
{
llist[0].setLocation(a.get(0),a.get(0));
g.drawstring(msg,200,200);
}
}
Firstly this looks suspicously like code from a tutorial. Secondly please use the code tags. And thirdly have you tried any of the online tutorials which refer to arrays/arraylists/collections?
List listA = new ArrayList();
List listB = new ArrayList();
for (int i = 0; i < 10; i++) {
System.out.println(" - Storing Integer(" + i + ")");
listA.add(new Integer(i));
}