---
title: "java面试题"
author: "gdntx"
date: "2009-08-12T14:40:58Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2009-12-23T10:27:55Z"
id: 445529
url: "https://gdntx.iteye.com/blog/445529"
---

**java交流群:38615496**

这是一道面试题

要求不能使用split()方法，实现一个功能。例如：将一个字符穿Sting="1\_2\_3\_4\_5\_6\_7\_8\_9",  
转变成字符串数组String\[]={"123","456","789"}.

 

解决方案一：

 

```
public class Test{

	public static void main(String[] args) {
		String str = "1_2_3_4_5_6_7_8_9";
		String arr = str.replaceAll("_", "");
		int index = 0;
		String[] arrstr = new String[arr.length() / 3];
		for (int i = 0; i < arr.length(); i += 3) {
			arrstr[index] = arr.substring(i, i+3);
			index++;
		}

		for (int j = 0; j < arrstr.length; j++) {
			System.out.println(arrstr[j]);
		}

	}
}
```

 大家有什么好的题目欢迎留言，感激不尽！！！