2013-06-14 2 views
-7

연락처 배열을 수행하는 방법? 그런 다음 문자열을 넣고 "$"를 구분 기호로 사용하는 방법은 무엇입니까?메인 클래스에서 연락처 배열을 만들 수

연락처의 배열을 만드는 기본 클래스에서 연락처를 입력합니다. 구분 기호로 "$"를 사용하여 문자열로 데이터를 넣어 입력 한 후

public class Contato { 

    private String name; 
    private String address; 
    private String numerophone; 

    public void setName(String name) { 
     this.name = name; 
    } 

    public void setAddress(String address){ 
     this.address = address; 
    } 

    public void setTelefone(String numerophone) { 
     this.numerophone = numerophone; 
    } 

    public String getName() { 
     return name; 
    } 

    public String getAddress() { 
     return address; 
    } 

    public String numerophone() { 
     return numerophone; 
    } 

    @Override 
    public String toString() { 
     return "name: " + this.name + " address : " + this.address + " fone : " + this.numerophone; 
    } 
} 
+3

문제는 무엇인가? –

+0

당신은 대답을 얻기 위해 질문을해야합니다 ... –

+0

연락처 배열을 수행하는 방법? –

답변

0
public static void main (String ... args) { 
    ArrayList<Contanct> contacts = new ArrayList<Contact>(); 

    Contact c1= new Contact(); 
    c1.setName("John"); 
    c1.setAddress("Arthur Street 10"); 
    c1.setTelephone("123"); 

    Contact c2= new Contact(); 
    c2.setName("Peter"); 
    c2.setAddress("Sam Street 2"); 
    c2.setTelephone("456"); 

    contacts.add(c1); 
    contacts.add(c2); 

    String result= ""; 
    //Put it to a String 
    for (Contact c : contacts) { 
     result+=c.toString() + "$"; 
    } 
    result = result.substring(0, result.length() - 1); 

    System.out.println(result); 
} 
+0

감사합니다 .. darijan =] –

0

는 연락처의 배열을 만듭니다

private static final int MAX_CONTACTS = 100; 
Contato[] contacts = new Contato[MAX_CONTACTS]; 
그런 다음 각 연락처에 액세스하는 배열을 통해 반복 할 수

:

for (Contato c : contacts) { 
    // Do something e.g. 
    c.setName("Will"); 
} 
0

당신이 "연락처의 배열을"방법을 그대로에 따라 시도 :

Contact[] foo = {contact1, contact2, contact3...}; 

또는

List<Contact> bar = new ArrayList<Contact>; 
bar.add(contact1); 
관련 문제