aspose file tools*
The moose likes Beginning Java and the fly likes which hirarcy methods will call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "which hirarcy methods will call " Watch "which hirarcy methods will call " New topic
Author

which hirarcy methods will call

akhter wahab
Ranch Hand

Joined: Mar 02, 2009
Posts: 151

here is a code



i like to know these method will perform operations on someThing but in which hirarcy i mean which method will do action first,second third etc


Start Earning Online||Start Earning Using Java
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

The methods are executed from left to right. The result of a method becomes the object on which the next method is invoked. Therefore all methods chained in this way must return some type instead of "void".

Marco
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

All but the last method must return something. Unless the result of the entire operation is saved in a variable, then also the last method must return something.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
Since Strings are immutable, the result of that operation will be lost unless that line is preceded by . . .

String text =

or similar.
akhter wahab
Ranch Hand

Joined: Mar 02, 2009
Posts: 151

Campbell Ritchie wrote:Since Strings are immutable, the result of that operation will be lost unless that line is preceded by . . .

String text =

or similar.


can you please explain this by example ... i didn't understand
regards
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10925
    
  12

someThing.toString().replaceAll("the ", "").trim().replaceAll("By ", "")

start at the beginning...you have 'someThing'. You call 'toString()' on it, which returns a string.

on THAT string, you call the 'replaceALL()' method, which returns a string.

on THAT string, you call 'trim()', which returns a string.

on THAT string, you call 'replaceAll()', which returns a string...

which is never saved. None of the string methods ever change the current string, they only build NEW strings and return those. So, you have done all this work, created (at least) four new strings, then never save what you get. You've basically done all this work for nothing. You would need to write something like



newString would then have the changes, and you could then use it somewhere.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
akhter wahab
Ranch Hand

Joined: Mar 02, 2009
Posts: 151

Thanks @fred rosenberger
1) i just place this code for understanding thats why not assigning this to any thing...
2) now one more Question arrise from your explanation that is

start at the beginning...you have 'someThing'. You call 'toString()' on it, which returns a string.

on THAT string, you call the 'replaceALL()' method, which returns a string.

on THAT string, you call 'trim()', which returns a string.

on THAT string, you call 'replaceAll()', which returns a string...
[/code]

can i get all these Strings not only resultant String from
[code=java]someThing.toString().replaceAll("the ", "").trim().replaceAll("By ", "")
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
akhter wahab wrote: . . . please explain this by example ... i didn't understand
regards
Fred has done so (Thank you Fred )
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
You would changetoThen you can retain the details of the intermediate Strings.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: which hirarcy methods will call
 
Similar Threads
Replace character ' in a string
escaping html characters and a string starting with double quote
String replace() method
remove line feed and carriage return from a string
Replace Carriage Returns in String