javasubset(javasubset函数)
华为云服务器特价优惠火热进行中! 2核2G2兆仅需 38 元;4核4G3兆仅需 79 元。购买时间越长越优惠!更多配置及优惠价格请咨询客服。
合作流程: |
本篇文章给大家谈谈javasubset,以及javasubset函数对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
微信号:cloud7591如需了解更多,欢迎添加客服微信咨询。
复制微信号
本文目录一览:
- 1、想问一下:java.util中,util是什么意思?谢谢
- 2、怎么用java实现apriori算法
- 3、最近在准备JAVA的考试.关于java TreeSet subSet的应用.
- 4、java树级对象递归查找子集问题
- 5、JAVA中String类能不能有子集,为什么?
- 6、JAVA递归找所有子集
想问一下:java.util中,util是什么意思?谢谢
Util是utiliy的缩写,是一个多功能、基于工具的包。
java.util是包含集合框架、遗留的 collection 类、事件模型、日期和时间设施、国际化和各种实用工具类(字符串标记生成器、随机数生成器和位数组、日期Date类、堆栈Stack类、向量Vector类等)。集合类、时间处理模式、日期时间工具等各类常用工具包。
Java的实用工具类库java.util包。在这个包中,Java提供了一些实用的方法和数据结构。例如,Java提供日期(Data)类、日历(Calendar)类来产生和获取日期及时间,提供随机数(Random)类产生各种类型的随机数,还提供了堆栈(Stack)、向量(Vector) 、位集合(Bitset)以及哈希表(Hashtable)等类来表示相应的数据结构。
Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程 。
Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点。Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等。
扩展资料
1、JDK(Java Development Kit)称为Java开发包或Java开发工具,是一个编写Java的Applet小程序和应用程序的程序开发环境。JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一些Java工具和Java的核心类库(Java API)。
2、不论什么Java应用服务器实质都是内置了某个版本的JDK。主流的JDK是Sun公司发布的JDK,除了Sun之外,还有很多公司和组织都开发了自己的JDK,例如,IBM公司开发的JDK,BEA公司的Jrocket,还有GNU组织开发的JDK。
3、另外,可以把Java API类库中的Java SE API子集和Java虚拟机这两部分统称为JRE(JAVA Runtime Environment),JRE是支持Java程序运行的标准环境 。
4、JRE是个运行环境,JDK是个开发环境。因此写Java程序的时候需要JDK,而运行Java程序的时候就需要JRE。而JDK里面已经包含了JRE,因此只要安装了JDK,就可以编辑Java程序,也可以正常运行Java程序。但由于JDK包含了许多与运行无关的内容,占用的空间较大,因此运行普通的Java程序无须安装JDK,而只需要安装JRE即可。
参考资料:百度百科——java.util

怎么用java实现apriori算法
from operator import and_from itertools import combinationsclass AprioriAssociationRule:
def __init__(self, inputfile):
self.transactions = []
self.itemSet = set([])
inf = open(inputfile, 'rb')
for line in inf.readlines():
elements = set(filter(lambda entry: len(entry)0, line.strip().split(',')))
if len(elements)0:
self.transactions.append(elements)
for element in elements:
self.itemSet.add(element)
inf.close()
self.toRetItems = {}
self.associationRules = []
def getSupport(self, itemcomb):
if type(itemcomb) != frozenset:
itemcomb = frozenset([itemcomb])
within_transaction = lambda transaction: reduce(and_, [(item in transaction) for item in itemcomb])
count = len(filter(within_transaction, self.transactions))
return float(count)/float(len(self.transactions))
def runApriori(self, minSupport=0.15, minConfidence=0.6):
itemCombSupports = filter(lambda freqpair: freqpair[1]=minSupport,
map(lambda item: (frozenset([item]), self.getSupport(item)), self.itemSet))
currentLset = set(map(lambda freqpair: freqpair[0], itemCombSupports))
k = 2
while len(currentLset)0:
currentCset = set([i.union(j) for i in currentLset for j in currentLset if len(i.union(j))==k])
currentItemCombSupports = filter(lambda freqpair: freqpair[1]=minSupport,
map(lambda item: (item, self.getSupport(item)), currentCset))
currentLset = set(map(lambda freqpair: freqpair[0], currentItemCombSupports))
itemCombSupports.extend(currentItemCombSupports)
k += 1
for key, supportVal in itemCombSupports:
self.toRetItems[key] = supportVal
self.calculateAssociationRules(minConfidence=minConfidence)
def calculateAssociationRules(self, minConfidence=0.6):
for key in self.toRetItems:
subsets = [frozenset(item) for k in range(1, len(key)) for item in combinations(key, k)]
for subset in subsets:
confidence = self.toRetItems[key] / self.toRetItems[subset]
if confidence minConfidence:
self.associationRules.append([subset, key-subset, confidence])
用Scala也大概六十多行:
import scala.io.Sourceimport scala.collection.immutable.Listimport scala.collection.immutable.Setimport java.io.Fileimport scala.collection.mutable.Mapclass AprioriAlgorithm(inputFile: File) {
var transactions : List[Set[String]] = List()
var itemSet : Set[String] = Set()
for (line-Source.fromFile(inputFile).getLines()) {
val elementSet = line.trim.split(',').toSet
if (elementSet.size 0) {
transactions = transactions :+ elementSet
itemSet = itemSet ++ elementSet
}
}
var toRetItems : Map[Set[String], Double] = Map()
var associationRules : List[(Set[String], Set[String], Double)] = List()
def getSupport(itemComb : Set[String]) : Double = {
def withinTransaction(transaction : Set[String]) : Boolean = itemComb
.map( x = transaction.contains(x))
.reduceRight((x1, x2) = x1 x2)
val count = transactions.filter(withinTransaction).size
count.toDouble / transactions.size.toDouble
}
def runApriori(minSupport : Double = 0.15, minConfidence : Double = 0.6) = {
var itemCombs = itemSet.map( word = (Set(word), getSupport(Set(word))))
.filter( wordSupportPair = (wordSupportPair._2 minSupport))
var currentLSet : Set[Set[String]] = itemCombs.map( wordSupportPair = wordSupportPair._1).toSet
var k : Int = 2
while (currentLSet.size 0) {
val currentCSet : Set[Set[String]] = currentLSet.map( wordSet = currentLSet.map(wordSet1 = wordSet | wordSet1))
.reduceRight( (set1, set2) = set1 | set2)
.filter( wordSet = (wordSet.size==k))
val currentItemCombs = currentCSet.map( wordSet = (wordSet, getSupport(wordSet)))
.filter( wordSupportPair = (wordSupportPair._2 minSupport))
currentLSet = currentItemCombs.map( wordSupportPair = wordSupportPair._1).toSet
itemCombs = itemCombs | currentItemCombs
k += 1
}
for (itemComb-itemCombs) {
toRetItems += (itemComb._1 - itemComb._2)
}
calculateAssociationRule(minConfidence)
}
def calculateAssociationRule(minConfidence : Double = 0.6) = {
toRetItems.keys.foreach(item =
item.subsets.filter( wordSet = (wordSet.sizeitem.size wordSet.size0))
.foreach( subset = {associationRules = associationRules :+ (subset, item diff subset,
toRetItems(item).toDouble/toRetItems(subset).toDouble)
}
)
)
associationRules = associationRules.filter( rule = rule._3minConfidence)
}}
我不建议用Java,应改用Python或Scala一类的语言。如果用Python,代码大概50行左右,但可以想像用Java便看起来复杂得多。看如下:
最近在准备JAVA的考试.关于java TreeSet subSet的应用.
Returns a view of the portion of this set whose elements range from fromElement to toElement. If fromElement and toElement are equal, the returned set is empty unless fromExclusive and toExclusive are both true. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.
The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.
Specified by: subSet(...) in NavigableSet
Parameters:
fromElement low endpoint of the returned set
fromInclusive true if the low endpoint is to be included in the returned view
toElement high endpoint of the returned set
toInclusive true if the high endpoint is to be included in the returned view
Returns:
a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive
Throws:
ClassCastException - if fromElement and toElement cannot be compared to one another using this set's comparator (or, if the set has no comparator, using natural ordering). Implementations may, but are not required to, throw this exception if fromElement or toElement cannot be compared to elements currently in the set.
NullPointerException - if fromElement or toElement is null and this set uses natural ordering, or its comparator does not permit null elements
IllegalArgumentException - if fromElement is greater than toElement; or if this set itself has a restricted range, and fromElement or toElement lies outside the bounds of the range.
Since:
1.6
因此这个方法是java1.6才加进去的,你看看你的jdk是不是1.5的
理论上subSet出来的Set只要你add进去的数在你subSet时候指定的区间之内就不会抛出异常了,你用jdk 1.6试试?
java树级对象递归查找子集问题
package com.demo.dept;
/**
* @author dongbin.yu
* @from 2016-05-06
* @since V1.0
*/
public class Dept {
private int id;
private String name;
private int parentId;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getParentId() {
return parentId;
}
public void setParentId(int parentId) {
this.parentId = parentId;
}
public Dept(int id, String name, int parentId) {
this.id = id;
this.name = name;
this.parentId = parentId;
}
}
package com.demo.dept;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author dongbin.yu
* @from 2016-05-06
* @since V1.0
*/
public class DeptTest {
private static ListDept depts = new ArrayList();
static{
depts.add(new Dept(1,"部门1",0));
depts.add(new Dept(2,"部门2",1));
depts.add(new Dept(3,"部门3",1));
depts.add(new Dept(4,"部门4",1));
depts.add(new Dept(5,"部门5",2));
depts.add(new Dept(6,"部门6",3));
depts.add(new Dept(7,"部门7",2));
depts.add(new Dept(8,"部门8",2));
depts.add(new Dept(9,"部门9",1));
depts.add(new Dept(10,"部门10",5));
}
public static void main(String[] args) {
MapInteger, ListInteger deptMap = new HashMap();
for (Dept dept : depts) {
deptMap.put(dept.getId(),getChildDept(dept.getId()));
}
System.out.println(deptMap);
}
private static ListInteger getChildDept(int id){
ListInteger ids = new ArrayList();
for (Dept dept : depts) {
if(dept.getParentId() == id){
//添加第一次父id符合的
ids.add(dept.getId());
//添加嵌套父id符合的
ids.addAll(getChildDept(dept.getId()));
}
}
Collections.sort(ids);
return ids;
}
}
JAVA中String类能不能有子集,为什么?
建议你看一下 String 类的 API,里面这么定义这个类的写的:
public final class Stringextends Objectimplements Serializable, ComparableString, CharSequence
String 类代表字符串。
Java 程序中的所有字符串字面值(如 "abc" )都作为此类的实例实现。
字符串是常量;它们的值在创建之后不能更改。。。。。
一个final类是无法被任何人继承的,那也就意味着此类在一个继承树中是一个叶子类,并且此类的设计已被认为很完美而不需要进行修改或扩展。对于final类中的成员,你可以定义其为final,也可以不是final。而对于方法,由于所属类为final的关系,自然也就成了final型的。你也可以明确的给final类中的方法加上一个final,但这显然没有意义。
当你将final用于类身上时,你就需要仔细考虑。
可以参见以下资料:
JAVA递归找所有子集
package web;
import java.util.ArrayList;
public class SubsetGenerator
{
int[] indexs = null;
int COUNT = 1;// choose how many to be combination
ArrayListString list = new ArrayListString ();
private String subsets;
public SubsetGenerator( String subsets )
{
this.subsets = subsets;
}
public ArrayListString getSubsets ( int... params )
{
if(params.length == 0)
{
indexs = new int[subsets.length ()];
params = new int[2];
params[0] = 0;
params[1] = -1;
list.add ("");
}
params[1]++;
if(params[1] COUNT - 1)
{
return list;
}
for( indexs[params[1]] = params[0]; indexs[params[1]] subsets.length (); indexs[params[1]]++ )
{
getSubsets (indexs[params[1]] + 1, params[1]);
if(params[1] == COUNT - 1)
{
String temp = "";
for( int i = COUNT - 1; i = 0; i-- )
{
temp += subsets.charAt (indexs[params[1] - i]);
}
list.add (temp);
}
}
if(COUNT subsets.length () params[0] == 0)
{
COUNT++;
getSubsets (0, -1);
}
return list;
}
}
package web;
import java.util.ArrayList;
import java.util.Collections;
public class SubsetGeneratorTester
{
public static void main ( String[] args )
{
SubsetGenerator generator = new SubsetGenerator ("rum");
ArrayListString subsets = generator.getSubsets ();
Collections.sort (subsets);
if(!"[, m, r, rm, ru, rum, u, um]".equals (subsets.toString ()))
{
System.err.println ("Expected: [, m, r, rm, ru, rum, u, um]");
}
else
{
System.err.println ("Congratulations !");
System.out.println ("Your result is: " + subsets);
}
}
}
关于javasubset和javasubset函数的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
