我正在制作一本地址簿。为此,我用了一个
ArrayList
但是它会出错
令牌上的语法错误“(”,此令牌后面的表达式
这是我的AddressBook类代码。我用过三节课。一个是包含人员信息的personInfo类,另一个是我目前面临问题的AddressBook类,第三个是主类或驱动类。请帮我解决这个问题
错误指向
persons = new ArrayList()<personInfo>();
import javax.swing.*;
import java.util.*;
public class AddressBook
{
ArrayList < personInfo > persons;
public AddressBook ()
{
persons = new ArrayList () < personInfo > ();
}
public void addPerson ()
{
String name = JOptionPane.showInputDialog ("Enter Person
Name");
String add = JOptionPane.showInputDialog ("Enter Address");
String ph = JOptionPane.showInputDialog ("Enter Phone Number");
personInfo p = new personInfo (name, add, ph);
persons.add (p);
}
public void searchPerson (String n)
{
for (int i = 0; i < persons.size (); i++)
{
personInfo p = (personInfo) persons.get (i);
if (n.equals (p.name))
{
p.print ();
}
}
}
public void deletePerson (String n)
{
for (int i = 0; i < persons.size (); i++)
{
personInfo p = (personInfo) persons.get (i);
if (n.equals (p.name))
{
persons.remove (i);
}
}
}
答案 0 :(得分:1)
persons = new ArrayList<personInfo>();