so I have this method which reads a file into an arrayList of strings and I want to swap 2 characters from 2 strings in the list, update the list and save it back to the file. I seem to have everything but the list update part working. When I try the .set() method I get an index out of bounds error and can't quite understand why
public class CharSwapper {
public static void linear(String name, int firstl,int first, int secondl,int second){
try{
List<String> lines = Files.readAllLines(Paths.get(name));
String one = Files.readAllLines(Paths.get(name)).get(firstl);
String two = Files.readAllLines(Paths.get(name)).get(secondl);
char sone[]=one.toCharArray();
char stwo[]=two.toCharArray();
char temp;
temp=sone[first];
sone[first]=stwo[second];
stwo[second]=temp;
String ssone=new String(sone);
String sstwo=new String(stwo);
//one=ssone;
//two=sstwo;
lines.set(firstl,ssone);
lines.set(secondl, sstwo);
FileWriter writer = new FileWriter(name);
for(String str: lines) {
writer.write(str+'\n');
}
System.out.println("Edit succesfull");
writer.close();