Hi, I'm trying to fix a string from "hollo werld" to "hello world". To do this, I made another string of what we want, turned both of them into char arrays, and iterated through, changing elements as needed in a for loop. Here's what I have:
Here's the method definition:
Here's where the method is called:package samsExperiments; public class StaticMethodExample { //fix "Hollo Werld" to "Hello World" public static String fixBadStr(char[] badStrToChars, char[] goodStrToChars) { for(int i = 0; i < badStrToChars.length; i++) { if(badStrToChars[i] != goodStrToChars[i]) { badStrToChars[i] = goodStrToChars[i];//badStrToChars[i].replace } } String backToStr = badStrToChars.toString(); return backToStr; } }
package samsExperiments; import java.util.Scanner; import java.util.Arrays; import java.util.ArrayList; import java.util.Vector; import java.util.Hashtable; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import java.util.Random; import static samsExperiments.StaticMethodExample.*; import java.lang.StringBuilder; import java.text.DecimalFormat; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Map; import customExceptions.IntegerOutOfRangeException; public class SamsExperimentsMain { public static void main(String[] args){ String badStr = "Hollo Werld"; String goodStr = "Hello World"; char[] badStrToChars = badStr.toCharArray(); char[] goodStrToChars = goodStr.toCharArray(); String backToStr = StaticMethodExample.fixBadStr(badStrToChars, goodStrToChars); System.out.println(backToStr); }//end of main method }//end of class
The output is "[C@55f96302". What happened? Why isn't the output "Hello World"?