「地址信息分析java」java中地址值是什么意思
本篇文章给大家谈谈地址信息分析java,以及java中地址值是什么意思对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
求java程序:用键盘向控制台输入一个E-mail地址,分析该地址获取并输出域名如:“126.co
import java.util.Scanner;
public class EmailAnalyzer {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 提示用户输入E-mail地址
System.out.print("请输入E-mail地址:");
String email = scanner.nextLine();
// 获取域名
int indexOfAtSign = email.indexOf('@');
String domain = email.substring(indexOfAtSign + 1);
// 输出域名
System.out.println("域名:" + domain);
}
}
关于Java的地址值和哈希值?
1、hashCode的存在主要是用于查找的快捷性,如Hashtable,HashMap等,hashCode是用来在散列存储结构中确定对象的存储地址的;
2、如果两个对象相同,就是适用于equals(java.lang.Object) 方法,那么这两个对象的hashCode一定要相同;
3、如果对象的equals方法被重写,那么对象的hashCode也尽量重写,并且产生hashCode使用的对象,一定要和equals方法中使用的一致,否则就会违反上面提到的第2点;
4、两个对象的hashCode相同,并不一定表示两个对象就相同,也就是不一定适用于equals(java.lang.Object) 方法,只能够说明这两个对象在散列存储结构中,如Hashtable,他们“存放在同一个篮子里”
如何用JAVA获取GOOGLE 地图经纬度,地址信息
第一步 、申请一个GOOGLE地图的KEY
1、根据地址获取经纬度
[java] view plain copy print?
public static void getGoogleLatLng() {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
// 创建httpget.
HttpGet httpget = new HttpGet("上海市sensor=falsekey=");
logger.debug("executing request " + httpget.getURI());
// 执行get请求.
CloseableHttpResponse response = httpclient.execute(httpget);
try {
// 获取响应实体
HttpEntity entity = response.getEntity();
logger.debug("--------------------------------------");
// 打印响应状态
System.out.println(response.getStatusLine());
if (entity != null) {
// 打印响应内容
String str = EntityUtils.toString(entity);
JSONObject o = (JSONObject) JSON.parse(str);
JSONArray o2 = (JSONArray) o.get("results");
JSONObject o3 = (JSONObject) o2.get(0);
JSONObject o4 = (JSONObject) o3.get("geometry");
JSONObject o5 = (JSONObject)o4.get("location");
logger.debug("lat===="+o5.get("lat")+";lng====="+o5.get("lng"));
}
logger.debug("------------------------------------");
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
logger.debug(e.getMessage());
} catch (ParseException e) {
e.printStackTrace();
logger.debug(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
logger.debug(e.getMessage());
} finally {
// 关闭连接,释放资源
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
logger.debug(e.getMessage());
}
}
}
2、根据经纬度获取地址信息
[java] view plain copy print?
public static String getGoogleAddres(BigDecimal lat, BigDecimal lng) {
String addr = "";
if(null == lat || null == lng){
return addr;
}
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
// 创建httpget.
HttpGet httpget = new HttpGet(MessageFormat.format("{0},{1}sensor=falselanguage=zh-CNkey=", lat, lng));
logger.debug("executing request " + httpget.getURI());
// 执行get请求.
CloseableHttpResponse response = httpclient.execute(httpget);
try {
// 获取响应实体
HttpEntity entity = response.getEntity();
logger.debug("--------------------------------------");
// 打印响应状态
System.out.println(response.getStatusLine());
if (entity != null) {
// 打印响应内容
String str = EntityUtils.toString(entity);
JSONObject o = (JSONObject) JSON.parse(str);
JSONArray o1 = (JSONArray)o.get("results");
JSONObject o2 = (JSONObject)o1.get(0);
if(null != o2){
addr = String.valueOf(o2.get("formatted_address"));
logger.debug("详细地址===="+addr);
JSONArray o3 = (JSONArray)o2.get("addressComponent");
logger.debug("地址明细===="+JSONArray.toJSONString(o3));
}
}
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
logger.debug(e.getMessage());
} catch (ParseException e) {
e.printStackTrace();
logger.debug(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
logger.debug(e.getMessage());
} finally {
// 关闭连接,释放资源
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
logger.debug(e.getMessage());
}
}
return addr;
}
地址信息分析java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java中地址值是什么意思、地址信息分析java的信息别忘了在本站进行查找喔。