But creates problem for my program.
My task is to replace a word in a String.(Without using inbuilt functions like split or using Tokenizer).
Can anybody provide any hints how to do this.
I tried using a character array but it is becoming messy as converting a char array to string is proving a bit of problem.
Snippet of my awkward code
String str="I am having breakfast";
String replacableword="breakfast";
String newword="dinner";
//String newstring="";
// The output after replacing the word is stored in a char array called newstring
char newstring []=new char[40]; char arrayofwords[][]=new char[30][40];
int i=0;
int w=0;
int len=str.length();
You cannot replace part of a String; Strings are immutable and have no methods allowing you to do that. You can use the replace/replaceAll methods to create a new String with the alterations, but the best thing to do for Strings you wish to alter is to use StringBuilder.
I won't tell you about using reflection because this is the beginners' forum.