用户输入的字符串为:
[you] <bodyType> <age category> [profession] <gender> [pregnant]
如何将方括号([])和尖括号(<>)中的String值提取到数组中?
[Java字符串提供了split()方法,因此您可以使用特定的字符(例如,字符“,”)进行分割:
String input = readInput(); //read the string from input String[] values = input.split(",");
参见here类似问题或阅读Oracle Reference documentation
您的问题最好通过使用正则表达式来解决,例如
(?<=[\[<]).*?(?=[]>])