SCJP刷题学习笔记(Part four)
public static void main (String [] args) throws IOException {Stream<Path> files = Files.walk(Paths.get(System.getProperty("user.home")));files.forEach (fName -> { //line n1try {Path aPath = fName.toAbsolutePath(); //line n2System.out.println(fName + ":"+ Files.readAttributes(aPath,BasicFileAttributes.class).creationTime());} catch (IOException ex) {ex.printStackTrace();}});}
class Vehicle {
int vno;
String name;
public Vehicle (int vno, String name) {
this.vno = vno;
this.name = name;
}
public String toString () {
return vno + ":" + name;
}
}
Set<Vehicle> vehicles = new TreeSet <> ();vehicles.add(new Vehicle (10123, "Ford"));vehicles.add(new Vehicle (10124, "BMW"));System.out.println(vehicles);
What is the result?
public static void main (String[ ] args) {
int i;
char c;
try (FileInputStream fis = new FileInputStream (“course.txt”);
InputStreamReader isr = new InputStreamReader(fis);) {
while (isr.ready()) { //line n1
isr.skip(2);
i = isr.read ();
c = (char) i;
System.out.print(c);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Part two 涉及到的FileInputStream类的使用:https://blog.csdn.net/chentiefeng521/article/details/51776218
public class Test<T> {
private T t;
public T get () {
return t;
}
public void set (T t) { this.t = t;
}
public static void main (String args [ ] ) {
Test<String> type = new Test<>();
Test type1 = new Test (); //line n1
type.set("Java");
type1.set(100); //line n2
System.out.print(type.get() + " " + type1.get());
}
}
class Vehicle {
String name;
void setName (String name) {
this.name = name;
}
String getName() {
return name;
}
}
public class Product {
int id; int price;
public Product(int id,int price) {
this.id = id;
this.price = price;
}
public String toString() { return id + ":" + price; }
}
List<Product> products = Arrays.asList(new Product(1, 10),
new Product (2, 30),
new Product (2, 30));
Product p = products.stream().reduce(new Product (4, 0), (p1, p2) -> {
p1.price+=p2.price;
return new Product (p1.id, p1.price);});
products.add(p);
products.stream().parallel()
.reduce((p1, p2) - > p1.price > p2.price ? p1 : p2)
.ifPresent(System.out: :println);
public class Book implements Comparator<Book> {
String name;
double price;
public Book () {}
public Book(String name, double price) {
this.name = name;
this.price = price;
}
public int compare(Book b1, Book b2) {
return b1.name.compareTo(b2.name);
}
public String toString() {
return name + “:” + price;
}
}
List<Book>books = Arrays.asList (new Book (“Beginning with Java”, 2), new book
(“A
Guide to Java Tour”, 3));
Collections.sort(books, new Book());
System.out.print(books);
List<String> listVal = Arrays.asList(“Joe”, “Paul”, “Alice”, “Tom”);
System.out.println (
// line n1
);
class Caller implements Callable<String> {
String str;
public Caller (String s) {this.str=s;}
public String call()throws Exception { return str.concat (“Caller”);}
}
class Runner implements Runnable {
String str;
public Runner (String s) {this.str=s;}
public void run () { System.out.println (str.concat (“Runner”));}
}
public static void main (String[] args) throws InterruptedException,ExecutionException {ExecutorService es = Executors.newFixedThreadPool(2);Future f1 = es.submit (new Caller ("Call"));Future f2 = es.submit (new Runner ("Run"));String str1 = (String) f1.get();String str2 = (String) f2.get(); //line n1System.out.println(str1+ ":" + str2);}
Explanation/Reference:
InterruptedException 异常:https://blog.csdn.net/derekjiang/article/details/4845757
Callable和Future:https://blog.csdn.net/ghsau/article/details/7451464
ExecutorService详解:https://blog.csdn.net/fwt336/article/details/81530581
public class Canvas implements Drawable {
public void draw () { }
}
public abstract class Board extends Canvas { }
public class Paper extends Canvas {
protected void draw (int color) { }
}
public class Frame extends Canvas implements Drawable {
public void resize () { }
}
public interface Drawable {
public abstract void draw ();
}
SCJP刷题学习笔记(Part four)相关推荐
- SCJP刷题学习笔记(Part one)
测试Java版本"1.8.0_131" 工具为eclipse QUESTION 1 Given the definition of the Vehicle class: class ...
- 手机号正则_一起刷题学习正则表达式
在我最开始学习正则表达式的时候看到一堆符号简直头晕,所以很长一段时间我都是百度一下某某正则怎么写,比如:匹配所有手机号码的正则,但是有时候工作中碰到的一些问题网上搜不到,这就尴尬了,后面还是逼着自己花 ...
- 力扣刷题学习SQL篇——1-8 查询(按日期分组销售产品——利用聚合函数GROUP_CONCAT)
力扣刷题学习SQL篇--1-8 查询(按日期分组销售产品--利用聚合函数GROUP_CONCAT) 1.题目 2.解法 3.group_concat() 1.题目 题目链接:https://leetc ...
- 各大编程语言、软件,电子电路刷题学习网站链接及微信公众号
20210813 增加一些公众号 一些对程序员有用的网站 https://mp.weixin.qq.com/s/GiEbcBSReaKrVezjGA9_fA 20210715:公众号:拓跋啊秀 资源: ...
- 神了,无意中发现一位1500道的2021LeetCode算法刷题pdf笔记
昨晚逛GitHub,无意中看到一位大佬的算法刷题笔记,感觉发现了宝藏!有些小伙伴可能已经发现了,但咱这里还是忍不住安利一波,怕有些小伙伴没有看到. 关于算法刷题的困惑和疑问也经常听朋友们提及.这份笔记 ...
- 无意中发现一位大佬的算法刷题pdf笔记
昨晚逛GitHub,无意中看到一位大佬(https://github.com/halfrost)的算法刷题笔记,感觉发现了宝藏!有些小伙伴可能已经发现了,但咱这里还是忍不住安利一波,怕有些小伙伴没有看 ...
- LeetCode刷题复盘笔记—1373. 二叉搜索子树的最大键值和
今日主要总结一下,1373. 二叉搜索子树的最大键值和 题目:1373. 二叉搜索子树的最大键值和 Leetcode题目地址 题目描述: 给你一棵以 root 为根的 二叉树 ,请你返回 任意 二叉搜 ...
- BZOJ 2038: [2009国家集训队]小Z的袜子(hose)【莫队算法裸题学习笔记】
2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec Memory Limit: 259 MB Submit: 9894 Solved: 4561 [Su ...
- 刷题学习—算法思想(动态规划下)
24.买卖股票的最佳时机系列 24.1买卖股票的最佳时机 你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票.设计一个算法来计算你所能获取的最大利润. 只能一笔交易 cla ...
最新文章
- 110道 Redis面试题及答案(最新整理)
- matlab ufunc,ufunc函数
- shell实例第18讲:利用gzexe加密shell脚本
- Redux从入门到进阶,看这一篇就够了!
- CSS之window的视图属性
- 玩转Nodejs日志管理log4js
- 推荐一个自动写paper的软件,让IEEE吐血泪奔
- Liferay中页面的权限控制
- html认识数字游戏大全,认识HTML列表元素
- javaweb项目通过F5负载,获取客户端真实ip
- HP5100常见错误代码
- java中后台的跳转_java后台跳转
- wc,鹅厂码农最常用的三大编程语言,Java竟然没上榜!
- 交比不变性 matlab,交比 | 迪沙格定理
- 深入理解读写锁ReentrantReadWriteLock
- 详解STM32 PMW计算中的“死区”
- 利用Qt制作QQ的登录及主界面
- 高中计算机教学工作计划,教学工作计划
- 数字电路实验怎么接线视频讲解_电工知识:三相电表怎么接线?2种接线方法一一讲解,实物对照...
- 【web前端开发】CSS文字和文本样式
热门文章
- 【区块链技术开发】 Solidity使用Truffle Box工具实现预构建模板、自动化部署、创建智能合约示例代码
- PS Suite Studio 初探
- 10 模拟SPI驱动PS2无线手柄
- 《Feature Pyramid Networks for Object Detection》论文阅读笔记
- office tab enterprise是什么:Office Tab Enterprise是超级微软office多标签插件---高效办公必备神器
- 呱呱视频技术难点分享:遇到和填上的那些坑
- 红外线发射器与接收器模块使用教学
- ROS入门——胡春旭老师《机器人开发实践》在ROS-Melodic下的编译
- 洛谷P1024 [NOIP2001 提高组] 一元三次方程求解 C++ 思路加代码
- TestNG开源插件Arrow介绍