社区
非技术区
帖子详情
Hashtable 和Vector的问题
HarlanC
2007-05-15 08:53:21
private Vector tagHistory=new Vector();
private Vector countHistory=new Vector();
Hashtable tagCounts = (Hashtable)countHistory.elementAt(tagHistory.size());
这句话该怎么理解呢?vector的值能复给hashtable么?
...全文
278
4
打赏
收藏
Hashtable 和Vector的问题
private Vector tagHistory=new Vector(); private Vector countHistory=new Vector(); Hashtable tagCounts = (Hashtable)countHistory.elementAt(tagHistory.size()); 这句话该怎么理解呢?vector的值能复给hashtable么?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
HarlanC
2007-05-15
打赏
举报
回复
它是怎样实现分层的以及标记层位置的,看不懂
HarlanC
2007-05-15
打赏
举报
回复
package xmlparsing1;
import java.util.*;
import java.io.*;
public interface WebParser
{
public Vector getElements(File file)throws Exception;
}
package xmlparsing1;
import java.util.*;
import java.io.*;
public class WebParserWrapper
{
public Vector getElements(File file)throws Exception
{
Vector elements=new Vector();
WebParser webParser=new XMLPaserWrapper();
elements =webParser.getElements(file);
}
}
HarlanC
2007-05-15
打赏
举报
回复
这是搜到的部分源代码,是基于SAX 的XML嵌套信息提取,但不全,请帮忙侃侃,我是新手,没接触过这方面的东西
package xmlparsing1;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import java.io.*;
import java.util.*;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
public class XMLParserWrapper extends DefaultHandler implements WebParser
{
private Vector tagHistory=new Vector();//记录在分析的过程中所在XML树中的位置
private Vector countHistory=new Vector();//记录每一种标记在它所在层中的位置
private Vector elements = new Vector(); //存放最后结果元素
int tagCountInt;//记录一层中该类标记的数量
public Vector getElements(File file)
{
//初始化变量
//创建XML分析器
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(file,this);
return elements;
}
public void startElement
( String namespaceURI,String localName,String qName,Attributes attr )
throws SAXException
{
String tag = qName.toString();
//更新标记在本层中的个数
Hashtable tagCounts = (Hashtable)countHistory.elementAt(tagHistory.size());// 返回指定索引处的组件
Integer tagCountInteger = (Integer)tagCounts.get(tag);
if(tagCountInteger!=null)
tagCountInt=tagCountInteger.intValue();
tagCountInt+=1;
tagCounts.remove(tag);// 从哈希表中移除该键及其相应的值。
tagCounts.put(tag,new Integer(tagCountInt));//put(K key, V value)
//将标记压入堆栈并重新开始记数
tagHistory.addElement(tag+"["+tagCount+"]");
countHistory.addElement(new Hashtable());
}
public void endElement( String namespaceURI,String localName,String qName )
throws SAXException
{
if(tagHistory.size()>0)//弹出栈顶标记
{
tagHistory.remove(tagHistory.size()-1);
countHistory.remove(countHistory.size()-1);
}
}
public void characters( char[] ch, int start, int length )
throws SAXException
{
for(int ti=0;ti<tagHistory.size();ti++)
{
tagKey=tagKey+"."+tagHistory.elementAt(ti);
elements.addElement(new SourceElement(tagKey+".#pc data[0]",thisText));
}
}
}
flyforlove
2007-05-15
打赏
举报
回复
Vector里面可以放任何东西。
但你的Vector都还是空的
[leetcode] 1016. Binary String With Substrings Representing 1 To N
Description Given a binary string S (a string consisting only of ‘0’ and '1’s) and a positive integer N, return true if and only if for every integer X from 1 to N, the binary representation of X is a substring of S. Example 1: Input: S = "0110", N = 3 Out
No.270 - LeetCode[1016] Binary String With Substrings Representing 1 To N - 暴力
判断从n到n/2即可,小于n/2都包含在其中。 暴力匹配即可 /* * @lc app=leetcode id=1016 lang=cpp * * [1016] Binary String With Substrings Representing 1 To N */ // @lc code=start class Solution { public: bool match(string& s, int loc, int k){ int N = s.length();
[字符串] leetcode 1016 Binary String With Substrings Representing 1 To N
problem:https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n/ 暴力枚举了一下所有子字符串可能对应的数字,统计是否达到N个,就过了。不知道有没有更快的方法。 class Solution { public: bool queryString...
【leetcode】1023. Binary String With Substrings Representing 1 To N
题目如下: Given a binary stringS(a string consisting only of '0' and '1's) and a positive integerN, return true if and only if for every integer X from 1 to N, the binary representation of X is a su...
非技术区
23,404
社区成员
70,507
社区内容
发帖
与我相关
我的任务
非技术区
Java 非技术区
复制链接
扫一扫
分享
社区描述
Java 非技术区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章