so why not instead of doing
void method1(String str)

you do
String method1(String str)?

have the method do
return "xxxxxx";

and you can have str1 sort of the way you want it
str1 = method1(str1);

You do have to be careful of multitthreading issues here though.

dave.

This is *WAY* off topic and I didn't want to answer this (but I did so be it)


"Singh, Sushil" wrote:

> Hi Mann:
>
> Thanks for your reply.
>
> I am providing you the listing of a small program:
>
> ================= Start of program ======================
> import java.lang.*;
>
> public class test
> {
>     public static void main(String args[])
>     {
>        String str1 = "AAAAAA";
>
>        method1(str1);
>        System.out.println("After returning from str1: " + str1);
>     }
>
>     static void method1(String str1)
>     {
>        System.out.println("str1: " + str1);
>        str1 = "xxxxxx";
>     }
>
> }  // End of test
> ===================== End of program ========================
>
> In this java program, I am setting value of variable str1=AAAAAAA and then I
> am calling another method which is just simply printing the value of str1
> and set again set a new value which is "xxxxxxx" but now if I print the
> value of str1 its containing the old value only.
>
> Actually my requirement is for servlet only.  I am using "AS/400 Record
> level of access", in order to access the DB2.  In servlets I am having lots
> of methods: method1 is for positioning of file pointer, method2 is for
> reading the record and so on.
> So in order to maintain the file pointer my requirement is to pass the AS400
> file object as reference.
>
> Thanks,
> Sushil
> Email:   [EMAIL PROTECTED]   (Personal)
>           [EMAIL PROTECTED]  (Official)
>
> -----Original Message-----
> From: Kito Mann [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 15, 1999 1:20 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Parameters passed by reference
>
> Sushil,
>
> First, this question is way off topic.
>
> All Objecs in Java are passed by reference. Objects include Strings and
> Arrays, but not the primitive types: (ints, chars, longs, floats, etc.).
>
> So, for instance, in the following excerpt:
>
> public void test()
> {
>   String s = "This is a string";
>   myMethod(s);
>   myMethod(s.clone());
>   myMethod2(5);
> }
>
> public  void myMethod(String s)
> {
>    System.out.println(s);
> }
>
> public void myMethod2(int i)
> {
>   System.out.println(i);
> }
>
> The first call to myMethod() is passing the variable "s" by reference; the
> second call is passing a _copy_ by reference, which is the closest you can
> get to passing an Object by value. The call to myMethod2() will _always_
> pass the variable by value, since the parameter is a primitive type and not
> an Object. You can't pass primitive types by reference, but you can use one
> of the wrapper Objects (Integer, Float, etc.) and pass those by reference.
>
> Kito D. Mann
> [EMAIL PROTECTED]
>
> [EMAIL PROTECTED]
> Wednesday December 15, 1999 09:27 AM
>
> Please respond to [EMAIL PROTECTED]
> To:   [EMAIL PROTECTED]
> cc:    (bcc: Kito Mann/PSG/Prudential)
> Subject:  Parameters passed by reference
>
> Hi,
>
> I would like to know that how can we pass a variable by REFERENCE to a
> method within the same class.
>
> I have read that in order to pass by reference, we have to pass the object
> itself.  But in my case I have to pass a variable say string to a method
> inside the same class.
>
> Thanks,
>
> Sushil
> Email:   [EMAIL PROTECTED]   (Personal)
>             [EMAIL PROTECTED]  (Official)
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

--
David Mossakowski              [EMAIL PROTECTED]
Programmer                           212.310.7275
Instinet Corporation

"I don't sit idly by, I'm planning a big surprise"

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to