Java / Android Developer, Trainer, Writer, Speaker

Saturday, January 24, 2015

On 10:12 AM by M Rubel in ,    2 comments

Like the article?

Array: An array is something more or less like a container of data. Array container contains same type of data.





Read More from Oracle >> Here!

Java Code for practicing:

import java.util.Arrays;
public class myarray {
public static  void main(String [] args) {

// declaring  an array in java
int[] javaArray = new int[10];

// array with values
String prof[] = {"lawyear", "engineer", "stupoid", "developer"};

// allowed but not preferred declaring java array
int buy[];
buy = new int[10];

// java array of numbers, integer
int javaNumberArray[] = {2,3,6,7,78,8};


int[] [] learn = { {1,2,3}, {4,5,6}, {7,8,9,81}, {10,11, 12} };
 

// how to print a java array length
System.out.println( " My Java Array leangth: "+ learn.length );

int s;
for( s=0; s < javaNumberArray.length; s++ ) {

System.out.println( "My Array output, according to index is: "+ javaNumberArray[s] );


}




// printing a 2d array in java
int p,q;
for( p=0; p < learn.length; p++ ) {
for(q=0; q< learn[p].length; q++ ) {

System.out.println(  learn[p][q] );


}

}


for(int n: javaNumberArray) {
   System.out.println("My Arrar Java Number is: "+ n);




int[] seo = {1,2,23,3,3,3,4,4,5,6,67,7,8,89,9,76,4,33,3,32 } ;

// print a java array in one line
System.out.println( "Size of SEO ArrAy is: "+ Arrays.toString(seo)) ;

// print a java 2d ( 2 dimentional ) array in one line
System.out.println( "Size of 2D Learn ArrAy is: "+ Arrays.deepToString(learn)) ;





}
}






Output:

 My Java Array length: 4
My Array output, according to index is: 2
My Array output, according to index is: 3
My Array output, according to index is: 6
My Array output, according to index is: 7
My Array output, according to index is: 78
My Array output, according to index is: 8
1
2
3
4
5
6
7
8
9
81
10
11
12
My Arrar Java Number is: 2
My Arrar Java Number is: 3
My Arrar Java Number is: 6
My Arrar Java Number is: 7
My Arrar Java Number is: 78
My Arrar Java Number is: 8
Size of SEO ArrAy is: [1, 2, 23, 3, 3, 3, 4, 4, 5, 6, 67, 7, 8, 89, 9, 76, 4, 33, 3, 32]
Size of 2D Learn ArrAy is: [[1, 2, 3], [4, 5, 6], [7, 8, 9, 81], [10, 11, 12]]

2 comments:

  1. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on update.
    Web Development Company in India

    ReplyDelete
  2. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

    Best Dental Clinic in Chennai | Best Dentists in Chennai | Dental Hospital in chennai

    ReplyDelete