How to Update a String Array

How to Update a String Array thumbnail
Java Programming Language Logo

An array stores collections of data that are of the same base data type. An array can consist of zero to many elements and are numbered starting with the numeral zero. The total number of data items in the array comprises the overall length and the specific position of the array that a data element is stored is the array index. In Java, arrays are able to have a base data type of strings, which consist of one or many ASCII characters and can be manipulated similarly to any other data type stored in an array through adding and subtracting data elements as well as modification of existing elements.

Things You'll Need

  • Java development environment
Show More

Instructions

    • 1

      Download the latest Java development environment if the computer does not have a current one installed.

    • 2

      Open your text editor for composing the Java program. Save the file with the name myStringArray.java.

    • 3

      Initiate the class myStringArray and assign a static array of strings with values.

      class myStringArray
      {
      static String[] myStringArray = {"Alabama", "Arkansas", "Florida", "Georgia", Kentucky"};

    • 4

      public static void main(String args[]){
      for(int i=0;i<5;i++)
      {
      System.out.println(myStringArray[i]);
      }
      }
      myStringArray[2] = "Vanderbilt";
      for(int i=0;i<5;i++)
      {
      System.out.println("/n After String Array Manipulation /n");
      System.out.println(myStringArray[i]);
      }
      }
      }// end Main
      }//end class definition

    • 5

      View the output of the string manipulation on the command console.
      Alabama Arkansas Florida Georgia Kentucky
      After String Array Manipulation
      Alabama Arkansas Vanderbilt Georgia Kentucky

Tips & Warnings

  • Read the JavaDocs on the string class in Java to learn advanced class manipulation options.

Related Searches:

Resources

  • Photo Credit WIkimedia Commons by Sun Microsystems

Comments

You May Also Like

Related Ads

Featured