This is my second day with Java. So far, I'm enjoying it quite a bit. It has the structure of C++ that I like, and with so much more utility (lots of type conversion built in)!

I've written a console program that allows a user to input text. That text is transliterated, then transcoded into base 31 groups of arbitrary length. That took lots of reading but I got it to work and I understand what's happening.

I am now trying to write a complementary program that takes the transcoded text and outputs the text originally typed using the first program. Something is happening in my code that I'm unsure how to explain.

First, the code snippet:

public static String decodeString (String InputString) {

        String DecodeResult="";
        String TempString1="";
        String TempString2 = "";
        int TempInteger=0;

        int InputStringLength = InputString.length();

        // Step 1: Find the "Magic Number"
        TempString2 = InputString.trim();
        System.out.println("String to Decode: " + TempString2);
        int MagicNumber = TempString2.indexOf(" ");
        System.out.println("Magic Number: " + MagicNumber);

        // Step 2: Convert this to something we can modify      
        TempString1 = TempString2.split(" ").toString(); // <--There is a Problem Here
        System.out.println("De-spaced String1: " + TempString1);

Now, the output:

String to Decode: 2S383 C3N3A 383C3 M3N11 2F3I3 P383G 383H3 N1F
Magic Number: 5
De-spaced String1: [Ljava.lang.String;@525483cd
::TempString2> [L
Exception in thread "main" java.lang.NumberFormatException: For input string: "[L"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:449)
        at java.lang.Integer.parseInt(Integer.java:499)
        at decodestring.Main.decodeString(Main.java:51)
        at decodestring.Main.main(Main.java:83)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

I'll be the first to admit the code needs some clean up work. This is just a proof of concept for educational purposes. Any ideas what I did to make this happen?

NOTE: I want to apologize for the title. My fingers are a bit too chilled for typing.

Recommended Answers

All 2 Replies

Result of split method is an array
from java doc:

public String[] split(String regex)

Yes, and the default return of toString() for an object is

getClass().getName() + '@' + Integer.toHexString(hashCode())

If you want to see all of the values in the array you will need to iterate them and print each individually or use Arrays.toString().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.