• Skip to main content
  • Skip to primary sidebar

Founder at work

Master the skills to create and launch your next SaaS company

  • About Me
  • Reviews
  • Resources
  • Community
  • Contact
  • Lessons
  • Series
  • Search
  • Login

How to work with arrays in java?

November 7, 2012 by Rick Hernandez Leave a Comment

Arrays are setup with like a coulomb or row, they can hold different type of value of values.
So how do you tell java to create an array? the syntax is simple but before that what type of array would you like to create? what is going to be storing? (integers, strings, boolean values, etc) once you have the the sytnax goes as follow [decelration][brackets][name] = [new] [int] [Number of array];

 int [] iArray = new int 10; 

Now that we know what an array what we can unveil the secrete of java,

have you ever wondered what this is?

 public static void main (String [] args) 

the args part about the piece of code simple says that arrays can be passed to this main method. Knowing this much arrays can be made easily but don’t get carried away, the array always set a default value for the type of array, so when a array is created the values get initialized for example

int = 0
double = 0.0
so on..
/*************************** Code Examples ******************************/

import java.util.Random;

public class ArrayDemo
{
  public void runDemo ()
  {
    int [] iArray; // decalre the bran new array
    iArray = new int [10];
    
    Random random = new Random (); // new random generator
    
    
    for (int i=0; i < iArray.length; i++) // get an assigment to the variables
    {
      iArray[i] = random.nextInt(100) + 1; //sets i to the array ouptuing the numbers from 0-9
      
      System.out.printf("%2d %3d\n", i, iArray[i]);  // gets executed from 0-9
      
      
    }
  }
}

/******************* Run Method ***************************/

public class ArrayDemoTest
  
{
  public static void main(String [] args)
  {
    ArrayDemo arrayDemo = new ArrayDemo();
    
    arrayDemo.runDemo();
  }// end of main
} // end of arraydemotest class
Rick Hernandez

I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

Filed Under: Java, Programming

Primary Sidebar

Learn How To Take Your Idea And Convert It Into An App From Scratch Even If You Have Never Written A Single Line Of Code.

  • How to Find Your Next Great App Idea
  • The Secret To Getting PAID To Build Your Own App
  • How To Create Your App (SaaS, Mobile, VR, AR, Game)
  • How To Monetize Your Apps
Learn More
4.82 Ratings

Copyright © 2025 · JSecademy Blog Theme on Genesis Framework · WordPress · Log in