merge multiple keywords into a string i am trying to write a program to take a random amount of multiple keywords from a String[] and merge them together into a String
    String keywords = "max,Max,Pro,pro,XS,xs,Xs,XR,xr,Xr,X,6,7,8,10,11,SE,se,Se,Plus,plus";
    String[] keywordArray = keywords.split(",");
    Random keywordSelector = new Random();
    int keywordIndex = keywordSelector.nextInt(21);
    String title = keywordArray[keywordIndex];

    System.out.println("iPhone " + title);

current output example: iPhone X
how can i change the code so that i can achieve desired output example?: iPhone X 6 Max Pro 10 11 SE

Try this.  You need to categorize the different aspects of the phone.


*

*categories separated by :

*within categories separated by ,
String keywords = "max,Max:Pro,pro:XS,xs,Xs,XR,xr,Xr,X:6,7,8,10,11:SE,se,Se:Plus,plus";

String [] elements = keywords.split(":");
String[][] categories = new String[elements.length][];

// create arrays of categories.
for (int i = 0; i < elements.length; i++) {
      categories[i] = elements[i].split(",");
}

Random r = new Random();
String title = "";

// generate a random one based on each array size.
for (String[] c : categories) {
      int idx = r.nextInt(c.length);
      title += c[idx] + " ";
}  

System.out.println("iPhone " + title);

Prints something similar to (it will be different each time);
iPhone Max pro Xr 6 se plus 



You could utilize an ArrayList to achieve what you desire without duplicates.
Your code could like this:
String keywords = "max,Max,Pro,pro,XS,xs,Xs,XR,xr,Xr,X,6,7,8,10,11,SE,se,Se,Plus,plus";
ArrayList<String> keywordArray = new ArrayList<String>(Arrays.asList(keywords.split(",")));
Random keywordSelector = new Random();
String title = "iPhone ";
for(int i=0; i<5;i++) {
int keywordIndex = keywordSelector.nextInt(keywordArray.size());
String keyword = keywordArray.get(keywordIndex);       
title = title + keyword + " ";
keywordArray.remove(keyword);
}
System.out.println(title);

Basiclly create a modifiable list, pick a keyword from it an remove it afterwards.

How about using streams?
Example:
public static void main(String[] args) {
    Long startTime = System.nanoTime();

    String keywords = "max,Max,Pro,pro,XS,xs,Xs,XR,xr,Xr,X,6,7,8,10,11,SE,se,Se,Plus,plus";
    String[] keywordArray = keywords.split(",");
    System.out.print("iPhone");

    long numberOfRandomKeywords = 5L;
    int lowerBound = 0;
    int upperBound = keywordArray.length + 1;
    int[] randomIndexes = new Random().ints(numberOfRandomKeywords, lowerBound, upperBound).toArray();

    Stream<String> keywordStreams = Arrays.stream(keywordArray);
    keywordStreams.forEachOrdered( x -> {
Map<String, Boolean> seenKeywords = new HashMap<>();
for(int index : randomIndexes){
if(keywordArray[index] == x && !seenKeywords.containsKey(x)) {
System.out.print(" " + x);
seenKeywords.put(x, true);
}
}
    }); 

    Long endTime = System.nanoTime();
    System.out.println("\nTime taken: " + (endTime - startTime)/1_000_000 + " ms");
}

Sample Output:

iPhone Xs xr 6 10 Plus
  Time taken: 52 ms