Java基础之集合框架——使用真的的链表LinkedList<>(TryPolyLine)
控制台程序。
public class Point {
// Create a point from its coordinates
public Point(double xVal, double yVal) {
x = xVal;
y = yVal;
}
// Create a point from another point
public Point(Point point) {
x = point.x;
y = point.y;
}
// Convert a point to a string
@Override
public String toString() {
return x+","+y;
}
// Coordinates of the point
protected double x;
protected double y;
}
import java.util.LinkedList;
public class PolyLine {
// Construct a polyline from an array of points
public PolyLine(Point[] points) {
// Add the points
for(Point point : points) {
polyline.add(point);
}
}
// Construct a polyline from an array of coordinates
public PolyLine(double[][] coords) {
for(double[] xy : coords) {
addPoint(xy[0], xy[1]);
}
}
// Add a Point object to the list
public void addPoint(Point point) {
polyline.add(point); // Add the new point
}
// Add a point to the list
public void addPoint(double x, double y) {
polyline.add(new Point(x, y));
}
// String representation of a polyline
@Override
public String toString() {
StringBuffer str = new StringBuffer("Polyline:");
for(Point point : polyline) {
str.append(" "+ point); // Append the current point
}
return str.toString();
}
private LinkedList<Point> polyline = new LinkedList<>();
}
public class TryPolyLine {
public static void main(String[] args) {
// Create an array of coordinate pairs
double[][] coords = { {1, 1}, {1, 2}, { 2, 3},
{-3, 5}, {-5, 1}, {0, 0} };
// Create a polyline from the coordinates and display it
PolyLine polygon = new PolyLine(coords);
System.out.println(polygon);
// Add a point and display the polyline again
polygon.addPoint(10, 10);
System.out.println(polygon);
// Create Point objects from the coordinate array
Point[] points = new Point[coords.length];
for(int i = 0; i < points.length; ++i)
points[i] = new Point(coords[i][0],coords[i][1]);
// Use the points to create a new polyline and display it
PolyLine newPoly = new PolyLine(points);
System.out.println(newPoly);
}
}
Java基础之集合框架——使用真的的链表LinkedList<>(TryPolyLine)的更多相关文章
- Java基础--说集合框架
版权所有,转载注明出处. 1,Java中,集合是什么?为什么会出现? 根据数学的定义,集合是一个元素或多个元素的构成,即集合一个装有元素的容器. Java中已经有数组这一装有元素的容器,为什么还要新建 ...
- 黑马程序员——【Java基础】——集合框架
---------- android培训.java培训.期待与您交流! ---------- 一.集合框架概述 (一)集合框架中集合类关系简化图 (二)为什么出现集合类? 面向对象语言对事物的体现都是 ...
- java基础37 集合框架工具类Collections和数组操作工具类Arrays
一.集合框架工具类:Collections 1.1.Collections类的特点 该工具类中所有的方法都是静态的 1.2.Collections类的常用方法 binarySearch(List< ...
- Thinking in java基础之集合框架(转载)
集合简介(容器)把具有相同性质的一类东西,汇聚成一个整体,就可以称为集合,例如这里有20个苹果,我们把每一个苹果当成一个东西(一个对象),然后我们借用袋子把这20个苹果装起来,而这个袋子就是集合(也叫 ...
- Java基础之集合框架(Collection接口和List接口)
首先我们说说集合有什么作用. 一.集合的作用 1.在类的内部,对数据进行组织: 2.简单而快速的搜索大数量的条目: 3.有的集合接口,提供一系列排列有序的元素,并且可以在序列中间快速的插入或者删除有关 ...
- java基础之集合框架
6.集合框架: (1)为什么出现集合类? 面向对象对事物的体现都是以对象的形式,为了方便对多个对象的操作,就对对象进行存储. 集合就是存储对象最常用的一种方式. (2)数组和集合都是容器,两者有何不同 ...
- Java基础之集合框架——使用堆栈Stack<>对象模拟发牌(TryDeal)
控制台程序. public enum Rank { TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, A ...
- Java基础之集合框架——使用集合Vector<>挑选演员(TryVector)
控制台程序. public class Person implements Comparable<Person> { // Constructor public Person(String ...
- Java基础之集合框架类及泛型简介
Collection接口 Collection 通用的常见方法 add()添加一个元素,可以指定脚标 addAll()将一个collection放入 clear()清除 remove()删除元素,返回 ...
随机推荐
- bash shell命令行选项与修传入参数处理
在编写shell程序时经常需要处理命令行参数,本文描述在bash下的命令行处理方式.选项与参数:如下命令行: ./test.sh -f config.conf -v --prefix=/home -f ...
- 一些浏览器的USER-AGENT
115浏览器的USER-AGENT 版本号:5.1.3.55 Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like G ...
- Yii源码阅读笔记(十六)
Model类,集中整个应用的数据和业务逻辑—— /** * Generates a user friendly attribute label based on the give attribute ...
- 20145317彭垚 java课程总结
课程总结 每周读书笔记链接汇总 第一周http://www.cnblogs.com/5317p/p/5248481.html 第二周http://www.cnblogs.com/5317p/p/527 ...
- intervention/image intervention/imagecache
http://image.intervention.io/ 安装两个包 composer require intervention/image composer require interventio ...
- 五一结束,北戴河,yy,差一点,不太敢
collectionView Cell 设置颜色,蓝色,但是其他cell颜色也蓝色了,因为只写了if 没写else if (indexPath.item == 0) { cell.background ...
- find grep 组合使用
1. 查找所有".h"文件 find /PATH -name "*.h" 2. 查找所有".h"文件中的含有"helloworld ...
- Python的安装
篇幅主要是别人的分享,我这里主要是添加注意点.我当初就是按照下面的图片开始安装python,安装的是python3.5,pyDev也是使用的博主的(还花了1资源分下载).但是运行程序时,一直显示 Er ...
- PBAP 1.0协议翻译(Part1)
添加vCard3.0 Spec的链接- http://tools.ietf.org/html/rfc2425- http://tools.ietf.org/html/rfc2426 寻找最新的Spec ...
- WGZX:javaScript 学习心得--2
转贴javascript心得(二) 标签: javascriptajaxweb开发htmlfirefox框架 2008-09-11 10:56 636人阅读 评论(0) 收藏 举报 分类: UI(2 ...