Need guidance on how to remove whitespace from output when using split

public class Main {
/**

  • Iterate through each line of input.
    */
    public static void main(String args) throws IOException {
    InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
    BufferedReader in = new BufferedReader(reader);
    String line;
    String parts;
    while ((line = in.readLine()) != null) {
    line = line.trim();
    parts = line.split(“;”);
    System.out.println(
    findIntersection(
    toIntArray(parts[0].split(“,”)),
    toIntArray(parts[1].split(“,”))
    )
    );
    }
    }
    private static String findIntersection(int input1, int input2){
    Set intersection = new LinkedHashSet<>();
for (int i = 0, j = 0; i < input1.length; i++){
  while (input1[i] > input2[j] && j < input2.length){
    j++;
  }
  if (input1[i] < input2[j]){
    continue;
  }
  else {
    intersection.add(input2[j++]);
  }
}

if (intersection.isEmpty()){
  return "";
}
String result = intersection.toString();
result = result.trim();
return result.substring(1, result.length() -1);

}

private static int toIntArray(String array){
int nums = new int[array.length];

for (int i = 0; i < array.length; i++){
  nums[i] = Integer.parseInt(array[i]);
}
return nums;

}
}

Output:
{1,2,3,4;3,4,5,6}

3, 4

Expected Output:
{1,2,3,4;3,4,5,6}
3,4
Hi, i need help with the code as the output have white space infront, i try removing the whitespace with trim() but it does not have any effect

Hello,
Welcome to the community.

It seems you asked the same question twice within an hour. Do they differ by any means? If not, could you please remove the other one? There’s no need for a duplicate.

I would also advise to reformat the code properly. When you want others to help, help them with as much info as possible. As is, it is difficult to read.
Including the imports would be appropriate too.
Can you tell more about the input?

Regards.