Static String Static String Array


Static String Static String Array

Summary: By the end of this tutorial "Static String Static String Array", you will come to know creation of static string and static string array.

Like static variables, static strings and static string arrays are also common in Java coding. The same rules of static variables are followed. The following program creates one static string array names1 and one static string persons. The elements of static string array are put into static string and printed.

public class StringArrayManipulations
{
  static String names1[] = { "Jyostna", "Srinivas", "Pradeep", "Chandu" }; 
  public static String persons = "";
  public static void main(String args[])
  {
    for(String str : names1)
    {
      persons += str+ ", ";
    }
    System.out.println(persons);
  }
}


Static String Static String Array
Output screen of StringArrayManipulations.java of Static String Static String Array

JDK 1.5, enhanced for loop is used to iterate the array elements.

Array related topics that increase array manipulation techniques

A few questions for you.

1. Can you code like this.

System.out.println(pow(2,4)); // Math class is not written

instead of traditional

System.out.println(Math.pow(2,4)); // Math is written

Ans: Yes, it is possible from JDK1.5 version with a new feature known as static imports.
2. Can you use C-lang printf() in Java with all %d and %s etc options.?
Ans: Yes, it is possible from JDK1.5 version.
3. Can you use C-lang enums in Java?
Ans: Yes, it is possible from JDK1.5 version.
4. What is the garbage collection mechanism in Java?
Ans: Garbage Collection – gc() and exit(0)
5. How to use the C++ destructor functionality where Java does not support destructors?
Ans: Java Destructor – finalize()

2 thoughts on “Static String Static String Array”

Leave a Comment

Your email address will not be published.