我有以下代码:
import java.util.Scanner;
public class Chapter11_ProjectPinochle {
public static void main(String[]args) {
Scanner sc=new Scanner(System.in);
String a;
System.out.println("Type in your pinochle deals: ");
a=sc.nextLine();
sc.close();
String[] deals=a.split("");
}
}
我需要将命名的字符串拆分"a"为16个间隔的数组。但是拆分的问题在于输入内容是这样的:ATKQQJ,AKQQ,KQQJN,A
。我需要将其拆分为16个部分,并将其保存到"deals."我尝试过的命名数组中,String[] deals=a.split("" && ",")
;但是显然这是无效的。我还尝试将String a拆分为2个单独的数组,然后将它们放在一起,但我意识到我不知道如何。我希望输出为["A","T","K","Q","Q","J","A","K","Q","Q","K","Q","Q","J","N","A"]
输入为时ATKQQJ,AKQQ,KQQJN,A
。我应该如何做到这一点?
问题来源:Stack Overflow
//Split it out into individual characters
System.out.println(Arrays.toString("ATKQQJ,AKQQ,KQQJN,A".replace(",", "").toCharArray()));
//Split it into strings of a single character
System.out.println(Arrays.toString("ATKQQJ,AKQQ,KQQJN,A".replace(",", "").split("")));
回答来源:Stack Overflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。