Arrays in Java

Posted on 2006-11-22
Medium Priority
Last Modified: 2010-03-31
Hi I’m bit confused about the array system. Could anyone help me, How to create an array system which, we can enter multiple items. For example an inventory system which hold more than one information per product. How to create it and how to display it? (Just in dos mode to understand the system)

Like a class named as computer
Serial number     - string         default:??????
Model                 - string         default: Unknown
Laptop                - Boolean      default: false
Year purchased    - integer       default: -1
Question by:mysiva
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
LVL 16

Accepted Solution

suprapto45 earned 1000 total points
ID: 18001358
You create the JavaBean for that and put it into a kind like ArrayList or etc.

public class Computer {
    private String serialNumber;
    private String model;
    private boolean laptop;
    private int yearPurchased;
public String getSerialNumber() {
    return this.serialNumber;
public void setSerialNumber(String serialNumber) {
    this.serialNumber = serialNumber;
public String getModel() {
    return this.model;
public void setModel(String model) {
    this.model = model;
public boolean getLaptop() {
    return this.laptop;
public void setLaptop(boolean laptop) {
    this.laptop = laptop;
public int getYearPurchased() {
    return this.yearPurchased;
public void setYearPurchased(int yearPurchased) {
    this.yearPurchased = yearPurchased;


Then later, you can use it like

ArrayList arr = new ArrayList();
Computer c1 = new Computer();


Author Comment

ID: 18001405
Could you please write the full code, thus I can see how it’s works; and develop it more
LVL 24

Assisted Solution

sciuriware earned 1000 total points
ID: 18001428
Make that:

    ArrayList<Computer> arr = new ArrayList<Computer>();  // Java 5 !

Other options:

     1) Give 'Computer' a full constructor :

            Computer u = new Computer(serial, model, false, 2006);

     2) Use an array sometimes:

            Computer[] list = new Computer[1000];

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 16

Expert Comment

ID: 18001432
How if you post your current codes / progress?

I may need to go for meeting and will be back in few hours time

LVL 24

Expert Comment

ID: 18001434
mysiva, that was almost the full code.
If that was enough (all the answers), first take a basic course in JAVA.


Expert Comment

ID: 18003120
LOL Sciuriware......


you can always do this

Object arrayName[4];

arrayName[1] = new Integer();
arrayName[2] = new String;

That'd be customized arrays... (i think it works...)

but use a class.. its much easier.
LVL 24

Expert Comment

ID: 18003236
I gave that answer to you in another question.


Expert Comment

ID: 18003427
What answer?

for which one?


Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question