Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 27th, 2004, 01:53 PM
Registered User
 
Join Date: May 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reusing String Arrays


  I am trying to reuse an array where eventually I am going to put AIX commands but I get compile errors when I try to reuse it. I am a newborn to Java. I don't want to enter the elements on an item by item basis and would rather not create a seperate array.

Excerpt

     // Create an Initial version of Command Array
     String[] command = { "a", "b", "c"};

     // Now try to reuse it to store new values. This is wrong
     command = {"d", "e", "f"};


Full Code is below..

import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;

public class arrays
{
  public static void main(String[] args)
 {
  try{

     // Create an Initial version of Command Array
     String[] command = { "a", "b", "c"};

     // Now try to reuse it to store new values. This is wrong
     command = {"d", "e", "f"};
    }
    catch( Exception e )
     { e.printStackTrace(); }
 }
}

Upon Trying to compile this I get the following Error Message:

arrays.java:18: illegal start of expression
     command = {"d", "e", "f"};
               ^
 
Old May 28th, 2004, 04:11 AM
Registered User
 
Join Date: Jan 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to uskiranj
Default

String[] command = { "a", "b", "c"};with this u have created an array of Strings
command[0] points to String instance "a"
command[1] ------>"b"
command[2] ------>"c"
command[3] ------>"d"

unlike in c/c++, in java there is no such pointer which points to the starting element in the array.
that's why we are not able to assign the one more arry to that
but it's valid in c/c++.

because of its an array of instances u can give the String variables at the time of initialisation only.able to modify the existing String






Similar Threads
Thread Thread Starter Forum Replies Last Post
Question on reusing code billb VBScript 0 August 18th, 2006 10:39 AM
reusing querys jc188 Beginning PHP 3 April 1st, 2006 02:28 AM
Reusing Images [email protected] Classic ASP Basics 0 July 19th, 2004 02:58 PM
AutoNumber Reusing numbers chelst1 Access 3 July 5th, 2004 03:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.