카테고리 없음

[java] 자바- "문자열"배열을 실제 배열로 구문 분석 [닫힘]

행복을전해요 2021. 2. 18. 17:45

You can ignore the first [ and the last ] as they are not making a difference. The you can split the string by the commas and get a String[]. You just need to iterate through that and fill up your int[][].

-------------------

가지고있는 문자열은 JSON 형식과 매우 유사합니다. gson과 같은 JSON 파서를 사용할 수 있습니다.

https://code.google.com/p/google-gson/

많은 것의 문자열 변형을 구문 분석 할 수 있습니다.

기본 fromJson은 매우 간단한 값 유형을 사용하기 때문에 작동 할 수 있지만 배열 유형을 명시 적으로 설정할 수도 있습니다.

Type listType = new TypeToken<Integer[][]>() {}.getType();
Integer[][] yourArray = new Gson().fromJson(text, listType);
-------------------

중첩 된 루프와 Integer.parseInt메서드를 사용합니다.



출처
https://stackoverflow.com/questions/22079867