java day_Java_Day7(上)

Java learning_Day7(上)

内容

常用类

枚举类型

常用类

String 类

java.lang.String 类代表不可变的字符序列。

String 类的常见构造方法:

String(String original)

创建一个 String 对象为 original 的拷贝。

String(char[] value)

用一个字符数组创建一个 String 对象。

String(char[] value, int offset, int count)

用一个字符数组从 offset 项开始的 count 个字符序列创建一个 String 对象。

String 类常用方法

1d33172c4fa226542265fec439b4431b.png

5fd11712d6f6d2f69252bdf0114c8b0b.png

静态重载方法

public static String valueOf(...) 可以将基本类型数据转换为字符串;

例如:

public static String valueOf(double d)

public static String vauleOf(int i)

方法 public String[] split(String regex) 可以将一个字符串按照指定的分隔符分隔,返回分隔后的字符串数组。

StringBuffer 类

java.lang.StringBuffer 代表可变的字符序列。

StringBuffer 和 String 类似,但StringBuffer 可以对其子串进行改变。

StringBuffer 类的常见构造方法:

StringBuffer()

创建一个不包含字符序列的“空”的 StringBuffer 对象。

StringBuffer(String str)

创建一个 StringBuffer 对象,包含与 String 对象 str 相同的字符序列。

StringBuffer 常用方法

重载方法 public StringBuffer append(…) 可以为该 StringBuffer 对象添加字符序列,返回添加后的该 StringBuffer 对象引用

ff9b2d58cc4c33ee6844546562fbe095.png

重载方法 public StringBuffer insert(…) 可以为该 stringBuffer 对象在指定位置插入字符序列, 返回修改后的该 stringBuffer 对象引用

b9edea9b04addeef9cb5d9292d1fb19d.png

方法 public StringBuffer delete(int start, int end) 可以删除从 start 开始到 end-1 为止的一段字符序列,返回修改后的该 StringBuffer 对象引用。

和 String 类含义类似的方法

e41532863bf625705a0d4e92db962553.png

方法 public StringBuffer reverse() 用于将字符序列逆序,返回修改后的该 StringBuffer 对象引用。

基本数据类型包装类

包装类(如:Integer,Double 等)这些类封装了一个相应的基本数据类型数值,并为其提供了一系列操作。

Math 类

java.lang.Math 提供了一系列静态方法用于科学计算;其方法的参数和返回值类型一般为 double 型。

d06905324a071203aa5e2c1c607215e3.png

File 类

java.io.File 类代表系统文件名(路径和文件名)。

File 类的常见构造方法:

public File(String pathname) 以 pathname 为路径创建 File 对象,如果 pathname 是相对路径,则默认的当前路径在系统的属性 user.dir 中存储。

public File(Sring parent, String child) 以 parent 为父路径, child 为子路径创建 File 对象。

File 的静态属性 String separator 存储了当前系统的路径分隔符。

示例

package file1.file2;

import java.io.*;

public class FileTest{

public static void main(String[] args) {

String separator = File.separator;

String filename = "myfile.txt";

String directory = "mydir1" + separator + "mydir2";

//String directory = "mydir1/mydir2"; linux

//String directory = "mydir1\\mydir2"; windows

File file = new File(directory ,filename);

if (file.exists()) {

System.out.println("文件名" + file.getAbsolutePath());

System.out.println("文件大小" + file.length());

} else {

file.getParentFile().mkdirs();

try {

file.createNewFile();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

注意:由于在在开头引入包,因此 file.getParentFile() 操作得到的文件夹应该是包的上一层文件夹而不是 java 文件的父文件夹

枚举类型

java.lang.Enum枚举类型

只能够取特定值的一个

使用 enum 关键字

是 java.lang.Enum 类型

实例:

public class TestEnum {

public enum myColor {red, green, yellow};

public static void main(String[] args) {

myColor m = myColor.red;

switch (m) {

case red:

System.out.println("red");

break;

case green:

System.out.println("green");

break;

case yellow:

System.out.println("yellow");

default:

System.out.println("");

}

}

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440504.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【FZU - 2202】犯罪嫌疑人(思维,假装建图,分类讨论)

题干: 福尔摩斯是个大侦探,他总是在解决疑难案件。这一次的案件也不例外,案件是这样的:有编号为1到N的N位嫌疑犯,他们其中有一个犯了罪,然后每个嫌疑犯都被询问,“哪一个人犯了罪?”犯罪嫌疑人…

java关键字 valotile_Java内存模型-jsr133规范介绍,java中volatile关键字的含义

最近在看《深入理解Java虚拟机:JVM高级特性与最佳实践》讲到了线程相关的细节知识,里面讲述了关于java内存模型,也就是jsr 133定义的规范。系统的看了jsr 133规范的前面几个章节的内容,觉得受益匪浅。废话不说,简要的介…

【HDU - 5050 】Divided Land (Java大数,大数进制转换,大数gcd)

题干: It’s time to fight the local despots and redistribute the land. There is a rectangular piece of land granted from the government, whose length and width are both in binary form. As the mayor, you must segment the land into multiple squar…

Java重载和重写6_深入理解Java中的重写和重载

深入理解Java中的重写和重载重载(Overloading)和重写(Overriding)是Java中两个比较重要的概念。但是对于新手来说也比较容易混淆。本文通过两个简单的例子说明了他们之间的区别。定义重载简单说,就是函数或者方法有同样的名称,但是参数列表不相同的情形&…

【Gym - 101608G】WiFi Password (区间或,线段树 或 按位处理+尺取 或 二分)

题干: Just days before the JCPC, your internet service went down. You decided to continue your training at the ACM club at your university. Sadly, you discovered that they have changed the WiFi password. On the router, the following question wa…

java框架讲解ppt_经典框架spring介绍课件.ppt

Wepull Information Service Spring-javaEE的春天 预习检查 根据你的理解,“依赖注入”是什么? 根据你的理解,谈谈“依赖注入”适于在项目中应用吗? 你理解的“面向方面编程(AOP)”是什么样的? Spring框架的内容和作用…

python 协程池gevent.pool_进程池\线程池,协程,gevent

目录1. 进程池与线程池2. 协程3. gevent4. 单线程下实现并发的套接字通信首先写一个基于多线程的套接字服务端:from socket import *from threading import Threaddef comunicate(conn):while True: # 通信循环try:data conn.recv(1024)if len(data) 0: breakconn.send(data.…

【ZOJ - 3963】Heap Partition (STLset,二叉树的性质,构造,贪心,思维)

题干: A sequence S {s1, s2, ..., sn} is called heapable if there exists a binary tree Twith n nodes such that every node is labelled with exactly one element from the sequence S, and for every non-root node si and its parent sj, sj ≤ si and j…

java poi 3.13_Java 读取Excl文件 (poi-3.13)

最近做项目遇到了读取Excel数据到数据库做数据的初始化。于是找一个。发现(poi-3.13)可以解决问题。可以解析两种格式(xlsx和xls)以下是实现的步骤1.下载poi3.13包,地址(http://poi.apache.org/download.html#POI-3.13)2.学习APi。接下来是还是demo来说明问题吧&…

【CodeChef - CLIQUED 】Bear and Clique Distances(建图,缩点技巧,思维)

题干: 解题报告: 主要就是在于怎么处理那个前K个点:组成一个团。换句话说,缩成一个点。先直接当成每个点多了k条边来处理,T了。想想也是啊,要是K1e5,那就是1e10条边了。。刚开始尝试了半天缩点&…

【HDU - 5649】DZY Loves Sorting(线段树,区间更新区间查询,思维,01缩数变换,线段树分割)

题干: DZY has a sequence a[1..n]a[1..n]. It is a permutation of integers 1∼n1∼n. Now he wants to perform two types of operations: 0lr0lr: Sort a[l..r]a[l..r] in increasing order. 1lr1lr: Sort a[l..r]a[l..r] in decreasing order. After doin…

php错误403_phpstudy访问文件报错403/Forbidden解决办法

使用phpstudy访问WWW目录下的文件时,浏览器提示Forbidden错误,没有访问权限。我在网上搜索了喝多资料以及本人亲自尝试过后,总结了一下两种方法。方法一:打开phpStudy,点击按键“其他选项菜单”>找到phpStudy配置&g…

【CodeForces - 294B】Shaass and Bookshelf(枚举,贪心,思维,组内贪心组间dp)

题干: Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelfs dimensions to be as small as possible. The thickness of the i-th book is ti and its pages width is equal to wi. The thickness of each book is eith…

mac php开发集成环境,MAC OS X下php集成开发环境mamp

之前苦于mac上搭建本地服务器之艰辛,找寻好久都没找到一款类似windows上集成的本地服务器环境,诸如phpstudy,xampp,appserv,虽说xampp也有mac版,但不知为何不是Apache启动不了,这里小编为大家分享了MAC OS X 下php集成…

知识点总结vector创建二维数组

vector构造函数通常含有两个参数 原型如下&#xff1a; vector( size_type num, const TYPE &val ); 数量(num)和值(val) - 构造一个初始放入num个值为val的元素的Vector方法1&#xff1a; #include <iostream> #include<vector> #include<algorithm&…

php获取手机目录,php如何获取手机型号

手机App中判断平台&#xff0c;可以根据$_SERVER[HTTP_USER_AGENT]中的内容来判断浏览器类型或手机平台。(推荐学习&#xff1a;PHP编程从入门到精通)iPhone UA&#xff1a;Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, l…

【CodeForces - 920E】Connected Components? (dsu,补图连通块,STLset+map,bfs 或bitset)

题干&#xff1a; You are given an undirected graph consisting of n vertices and edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of vertices…

php获取post全部数据,PHP获取POST数据的几种方法汇总_PHP教程

PHP获取POST数据的几种方法汇总本文给大家汇总介绍了PHP获取POST数据的几种常用方法&#xff0c;这里分享给大家&#xff0c;有需要的小伙伴来参考下吧。一、PHP获取POST数据的几种方法方法1、最常见的方法是&#xff1a;$_POST[‘fieldname’];说明&#xff1a;只能接收Conten…

yiilite.php,缓存 - yii在哪些情况下可以加载yiilite.php?

yii权威指南上说&#xff0c;在开启apc缓存的情况下&#xff0c;可以加载yiilite.php提升性能。我有以下几点疑问&#xff1a;1.开启apc缓存的情况下&#xff0c;引入yiilite.php能提升性能的原因是因为缓存了opcode的关系么&#xff1f;2.使用其他缓存服务缓存opcode的情况下&…

【HDU - 1024 】Max Sum Plus Plus (dp及优化,最大m子段和)

题干&#xff1a; Now I think you have got an AC in Ignatius.Ls "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem. Given a consecutive number sequence…