Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

StringBuffer.reverse();

Name: Anonymous 2008-01-14 5:10

public class MainClass {
  public static void main(String args[]) {
    StringBuffer sb1 = new StringBuffer("abcde");
    sb1.append("abcdefghij");
    StringBuffer sb2 = sb1.reverse();
    System.out.println(sb1);
    System.out.println(sb2);
  }
}


Why the fuck is jihgfedcbaedcba also being assigned to sb1?

Name: Anonymous 2008-01-14 5:21

>>1
Because sb1.reverse() tells sb1 to reverse itself.

See http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html#reverse()

Name: Anonymous 2008-01-14 5:30

I know, but I thought that value would only be assigned to sb2, not actually stored in sb1 as well.

Name: Anonymous 2008-01-14 5:41

lol pointers

Name: Anonymous 2008-01-14 6:13

module Main where

main = do putStrLn $ sb1
          putStrLn $ sb2
    where sb1 = "abcde"
          sb2 = reverse sb1


Superior language is superior.

Name: Anonymous 2008-01-14 6:14

>>5
Oh, the $s aren't needed, I had them originally for putStrLn $ reverse "abcde". putStrLn sb1 is fine.

Name: Anonymous 2008-01-14 6:55

>>3
That's why you read the API. It reverses in place, and then returns a reference to this for no particular reason.
So not only do sb1 and sb2 have the same value in your example, they're the same object.

Name: Anonymous 2008-01-14 9:28

>>7
returns a reference to this for no particular reason.
It's so you can do sb.append(1).append("penis").reverse().append("aaaaaaa");

Name: Anonymous 2008-01-14 10:35

>>6
OH GOD NO
HASKELL HAS BECOME POPULAR, NOW EVEN PEOPLE LIKE YOU ARE USING IT
:(
:(

Name: Anonymous 2008-01-14 10:44

It reverses in place, and then returns a reference to this for no particular reason.
It would be quite nice in the forced indentation of code if you want to iterate through an array backwards.
for i in range(len(a)).reverse()
TOO BAD THE REVERSE METHOD RETURNS NOTHING SO YOU HAVE TO DO SOME STUPID SHIT LIKE range(len(a))[::-1]

Name: Anonymous 2008-01-14 11:03

>>10
for i in reversed(a):
    ...

Name: Anonymous 2008-01-14 11:16

>>8
I thought it was smart enough to walk all the way down to sb (or whichever the first actual object is) if the return type is void. Isn't it?

Name: Anonymous 2008-01-14 12:26

>>11
Why is it that when I google (for ``python reverse range'') I get shit like
http://www.python.org/search/hypermail/python-1992/0107.html
http://mail.python.org/pipermail/python-list/2003-January/181339.html
http://simonwillison.net/2004/Jan/28/sequenceInReverse/
and when I come bitching about it on /prog/ there's someone who corrects me with something elegant?

Name: Anonymous 2008-01-14 12:34

>>12
I thought it was smart enough to realize I didn't REALLY want to launch the missiles

Name: Anonymous 2008-01-14 12:40

>>14
Except that the behavior in >>12 is intuitive and unambiguous, not nearly in the mind-reading category.

Name: Anonymous 2008-01-14 12:52

>>15
Except that it isn't.

Name: Anonymous 2008-01-14 13:07

>>13
Because all those articles are old, and reversed() was only introduced in 2.4 - http://www.python.org/dev/peps/pep-0322/

Name: Anonymous 2008-01-14 13:10

SPOILER: You should use StringBuilder.

Name: Anonymous 2008-01-14 13:31

>>16
You're a worthless faggot and also wrong.

>>18
SPOILER: string manipulations in Java automatically use StringBuilder where possible.

Name: Anonymous 2008-01-14 13:34

>>19
Not if you explicitly create a StringBuffer, dumbass.

Name: Anonymous 2008-01-14 13:52

>>19
It's no fun when someone else is right, huhn.

Name: Anonymous 2008-01-14 14:00

>>3
It's what we call a destructive function. It just happens to return a reference to the object itself, so that you can chain stuff like ".toUpper().reverse()" and such.

Name: Anonymous 2008-01-14 16:04

>>22
Try to read before replying.

Name: Anonymous 2008-01-14 22:02

sb.append(1).append("penis").reverse().append("aaaaaaa");

(reverse $ sb ++ show 1 ++ "penis") ++ "aaaaaaa"

(++"aaaaaaa") . reverse . (++"penis") . ((++) $ show 1) $ sb

Name: Anonymous 2009-03-06 13:02

Place Women and kids should stay the   fuck away from   many ups and   indirection or 2   minutes Remove egg   Rub the flour   until sifted Stir   for 2 minutes   uf using before   my own searcher   with some shitty   script for a   SONG THAT I   can use Visual   vertical line movement.

Name: Anonymous 2009-03-06 13:24


The wars and unite.

Name: Anonymous 2011-02-04 13:42


Don't change these.
Name: Email:
Entire Thread Thread List