please help editing arrays in java -
i'm having hard time creating address book of mine, , im new @ this. thing want know if possible edit or modify values inside array,
string lname[] = new string[size]; string fname[] = new string[size]; string address[] = new string[size]; string contact[] = new string[size]; if example assigned john dor in fname array how edit value without going through whole process again since want replace r e john doe. given address there , addresses contain large strings...
well, relatively easy, normal string arrays can point using index such follows, plus assigning new string or using method such replace ... check out:
string fname[] = new string[1]; fname[0] = "john dor"; system.out.println("fname #1: " + fname[0]); // prints john dor // using replace change letter fname[0] = fname[0].replace('r', 'e'); system.out.println("fname #2: " + fname[0]); // prints john doe // replacing new string fname[0] = "john dor"; system.out.println("fname #3: " + fname[0]); // prints john dor fname[0] = "john doe"; system.out.println("fname #4: " + fname[0]); // prints john doe problem string arrays need know size of them when initializing, prefer arraylist's instead. take of source: arraylist example
Comments
Post a Comment