শুরু করা যাক তাহলে-
১. প্রথমে StringArrayExample নামে class তৈরি করি। নিচের কোড লক্ষ্য করি।
This file contains 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
package com.edupointbd.amirul; | |
public class StringArrayExample { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
// declare a string array with initial size | |
String[] progrmmingBook = new String[4]; | |
// add elements to the array | |
progrmmingBook[0] = "Programming in C "; | |
progrmmingBook[1] = "Java "; | |
progrmmingBook[2] = "C++"; | |
progrmmingBook[3] = "Python"; | |
String[] schoolbag2 = { "Bangla", "English", "Science", "Arts" }; | |
// print the third element of the string array | |
System.out.println("The third element is: " + schoolbag2[2]); | |
// iterate all the elements of the array | |
int size = schoolbag2.length; | |
System.out.println("The size of array is: " + size); | |
for (int i = 0; i < size; i++) { | |
System.out.println("Index[" + i + "] = " + schoolbag2[i]); | |
} | |
// iteration provided by Java 5 or later | |
for (String str : progrmmingBook) { | |
System.out.println(str); | |
} | |
} | |
} |
The third element is: Science
The size of array is: 4
Index[0] = Bangla
Index[1] = English
Index[2] = Science
Index[3] = Arts
Programming in C
Java
C++
Python