Bob Bob - 5 months ago 15
Java Question

Storing multiple inputs in an Array

Hello guys I still learning Java specifically arrays what I m trying to do is create sort of a mini database. I want to retrieve a name, phone number, and email address and when I call upon a name I want that information to be displayed here is what I got so far:

private static String [][] info;
private static String name;
private static ArrayList<String> nArray = new ArrayList<>();
private static ArrayList<String> pArray = new ArrayList<>();
private static ArrayList<String> eArray = new ArrayList<>();

public static void addCustomer()
Scanner new_customer = new Scanner(;

System.out.print("Name: ");
name = new_customer.nextLine();

System.out.print("Phone Number: ");
String phone = new_customer.nextLine();

System.out.print("E-Mail Address: ");
String email = new_customer.nextLine();
public static void customerInfo()
int totalCustomers = nArray.size();
System.out.print("Current Customers : "+totalCustomers+" Total\n");
StringBuilder arrayOutput = new StringBuilder();
for ( String name : nArray) {
String text = arrayOutput.toString();


If what you wanted to do is be able to display a particular customers info based on their name then one way you could do it is by looping through the nArray and comparing the values.

public static int getCustomerIndex(String name){
    for (int q = 0; q < nArray.size(); q++){
        if (name.equals(nArray.get(q))){
            return q;
    return -1;

public static void displayCustomer(int index){
    System.out.println("Name: " + nArray.get(index));
    System.out.println("Phone #: " + pArray.get(index));
    System.out.println("Email: " + eArray.get(index));

Bu really you will probably want to make a class Customer instead of having 3 different ArrayList.