Created
November 11, 2019 18:13
-
-
Save inan-mahmud/8bbee95cbec7cf628b2fcfa0f6e2a820 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Contact { | |
private String name; | |
private int id; | |
private String phoneNumber; | |
@Override | |
public String toString() { | |
return "Contact{" + | |
"name='" + name + '\'' + | |
", id=" + id + | |
", phoneNumber='" + phoneNumber + '\'' + | |
'}'; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getPhoneNumber() { | |
return phoneNumber; | |
} | |
public void setPhoneNumber(String phoneNumber) { | |
this.phoneNumber = phoneNumber; | |
} | |
public Contact(String name, int id, String phoneNumber) { | |
this.name = name; | |
this.id = id; | |
this.phoneNumber = phoneNumber; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collections; | |
public class Main { | |
public static void main(String[] args) { | |
// write your code here | |
ArrayList<Contact> contactArrayList = new ArrayList<>(); | |
Contact contact = new Contact("Rami",5,"12312"); | |
contactArrayList.add(new Contact("Inan",1,"01842101717")); | |
contactArrayList.add(new Contact("Sayeed",2,"12312132")); | |
contactArrayList.add(new Contact("Ekanto",3,"0184232101717")); | |
contactArrayList.add(new Contact("Robin",4,"018122142101717")); | |
contactArrayList.add(contact); | |
for (int i = 0; i < contactArrayList.size(); i++) { | |
System.out.println(contactArrayList.get(i)); | |
} | |
contactArrayList.remove(0); | |
System.out.println("----------------------------------\n\n"); | |
for (int i = 0; i < contactArrayList.size(); i++) { | |
System.out.println(contactArrayList.get(i)); | |
} | |
System.out.println(contactArrayList.size()); | |
System.out.println(contactArrayList.indexOf(contact)); | |
for (int i = 0; i < contactArrayList.size(); i++) { | |
System.out.println(contactArrayList.get(i)); | |
} | |
ArrayList<Contact> pcontactArrayList = new ArrayList<>(); | |
// Contact contact = new Contact("Rami",5,"12312"); | |
pcontactArrayList.add(new Contact("sfds",1,"01842101717")); | |
pcontactArrayList.add(new Contact("sdfs",2,"12312132")); | |
pcontactArrayList.add(new Contact("Eerterekanto",3,"0184232101717")); | |
pcontactArrayList.add(new Contact("gfrgf",4,"018122142101717")); | |
contactArrayList.addAll(pcontactArrayList); | |
System.out.println(Arrays.toString(contactArrayList.toArray())); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Addition { | |
/** | |
* | |
* @param n1 | |
* @param n2 | |
* | |
*/ | |
static void add(int n1,int n2){ | |
System.out.println(n1+n2); | |
} | |
static int add(int n1, int n2,int n3){ | |
return n1+n2+n3; | |
} | |
static void add(){ | |
System.out.println(1+2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment