---
title: "java面试题"
author: "gdntx"
date: "2009-08-13T13:13:19Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2011-05-21T09:11:02Z"
id: 446269
url: "https://gdntx.iteye.com/blog/446269"
---

**java交流群:8056902**

这也是一个面试题跟大家分享一下。

给一个任意字符组成的字符串统计每个字符出现的次数，例如：String str = "java@list#有中文啊,jiu  
zhemechangle",要求只用一个for循环或while循环；

```
	String str = "java@list#有中文啊,jiuzhemechangle";
		Map map = new HashMap();
		
		for (int i = 0; i < str.length(); i++) {
			if (!map.containsKey(str.charAt(i))) {
				map.put(str.charAt(i), 1);
			}else{
				Integer k = (Integer) map.get(str.charAt(i));
				k++;
				map.put(str.charAt(i), k);
			}
		}
```

 大家有什么好算法或者什么好的面试题欢迎留言，谢谢

 

本文转自己：[http://www.baixin.org/read.php?tid=10](http://www.baixin.org/read.php?tid=10 "百信网")   转载请注明出处！