我们是否可以使用一个键和两个值来实现HashMap.就像HashMap一样?
请帮助我,还告诉(如果没有办法)任何其他方式来实现三个值的存储,其中一个作为键?
作为我项目的一部分,我需要通过给出一组数字来创建非重复的2或3位随机数.我不想为此实现列表或数组,因为每个函数调用我应该得到1个随机数.
我尝试使用SecureRandom类的Java来做到这一点.我也得到了一些网站的帮助,但是我被困在中间,我们可以洗掉VALUES并完成它吗?但我不知道如何做到这一点.谁能帮我?
import java.security.SecureRandom;
public class RandomNumber {
private static final RandomNumber rnd= new RandomNumber();
private static final char[] VALUES = new char[] {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
private static final SecureRandom srn= new SecureRandom();
public String createID()
{
byte[] bytes = new byte[3];
srn.nextBytes(bytes);
}
Run Code Online (Sandbox Code Playgroud) 我正在做一个程序,我需要将枚举值插入HashMap.我们真的能这样做吗?我在很多方面尝试过它,但失败了.
谁能帮帮我吗?通过该程序,我需要实现一个包含4个线程池(其名称作为键)的HashMap,对应于我有一个ThreapoolExcecutor对象.
下面给出的是我的代码:
public class MyThreadpoolExcecutorPgm {
enum ThreadpoolName
{
DR,
PQ,
EVENT,
MISCELLENEOUS;
}
private static String threadName;
private static HashMap<String, ThreadPoolExecutor> threadpoolExecutorHash;
public MyThreadpoolExcecutorPgm(String p_threadName) {
threadName = p_threadName;
}
public static void fillthreadpoolExecutorHash() {
int poolsize = 3;
int maxpoolsize = 3;
long keepAliveTime = 10;
ThreadPoolExecutor tp = null;
threadpoolExecutorHash = new HashMap<String, ThreadPoolExecutor>();
ThreadpoolName poolName ;
tp = new ThreadPoolExecutor(poolsize, maxpoolsize, keepAliveTime,
TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5));
threadpoolExecutorHash.put(poolName,tp); //Here i am failing to implement currect put()
}
Run Code Online (Sandbox Code Playgroud) 我在这里经历了与此主题相关的几乎所有问题.但是无法得到适当的解决方案.
我的问题如下:
我创建了一个简单的程序来解组我有一个xsd的xml文件.我能够成功地做到这一点.但是,如果我在没有xsd的情况下获得xml,如果xml看起来像这样,我怎么能从中得到我的属性:
<items>
<item>
<code>12000</code>
<name>Samsung 620</name>
<price>9999</price>
</item>
<item>
<code>15000</code>
<name>NOKIA</name>
<price>19999</price>
</item>
<item>
<code>18000</code>
<name>HTC 620</name>
<price>29999</price>
</item>
</items>
Run Code Online (Sandbox Code Playgroud)
在这里,我没有xsd来生成我的类.我该怎么办?请帮助我.
谢谢
我创建了一个解组我的xml(item.xml)文件的方法.但是如果有多个元素,我如何遍历所有元素并显示它们?
我的代码如下:
final JAXBContext jc = JAXBContext.newInstance("com.generated");
final Unmarshaller u = jc.createUnmarshaller();
final File f = new File("D:\\item.xml");
final JAXBElement element = (JAXBElement) u.unmarshal(f);
final Item item = (Item) element.getValue();
// This will be helpful only if the xml contains one element
System.out.println(item.getCode());
System.out.println(item.getName());
System.out.println(item.getPrice());
Run Code Online (Sandbox Code Playgroud)
如果我的xml是
<item>
<item1>
<code>12000</code>
<name>Samsung Galaxy Tab 620</name>
<price>9999</price>
</item1>
<item2>
<code>15000</code>
<name>NOKIA</name>
<price>19999</price>
</item2>
<item3>
<code>18000</code>
<name>HTC 620</name>
<price>29999</price>
</item3>
</item>
Run Code Online (Sandbox Code Playgroud)
如何显示所有值?谁能帮我?
我之前也发过了类似的问题.我也澄清了我的怀疑.但我还需要更多东西.将使用枚举对象作为键并将线程池实例作为值来初始化Hashmap.我很困惑如何为其他进程调用的每个对象初始化HashMap.要弄清楚:我的程序MyThreadpoolExcecutorPgm.java初始化一个HashMap我的Progran AdditionHandler.java通过传递ThreadpoolName(枚举)从HashMap请求一个线程).我收到"来自HashMap的无线程"消息.请帮帮我.
下面给出的是我的代码:
public class MyThreadpoolExcecutorPgm {
enum ThreadpoolName {
DR, BR, SV, MISCELLENEOUS;
}
private static String threadName;
private static HashMap<ThreadpoolName, ThreadPoolExecutor>
threadpoolExecutorHash;
public MyThreadpoolExcecutorPgm(String p_threadName) {
threadName = p_threadName;
}
public static void fillthreadpoolExecutorHash() {
int poolsize = 3;
int maxpoolsize = 3;
long keepAliveTime = 10;
ThreadPoolExecutor tp = null;
threadpoolExecutorHash = new HashMap<ThreadpoolName, ThreadPoolExecutor>();
for (ThreadpoolName poolName : ThreadpoolName.) // failing to implement
{
tp = new ThreadPoolExecutor(poolsize, maxpoolsize, keepAliveTime,
TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5));
threadpoolExecutorHash.put(poolName, tp);
} …Run Code Online (Sandbox Code Playgroud) 我正在使用四个for循环来使用以下代码生成一组数字的VB程序.....
For sphere = 1 To 10
For cylinder = 2 To 20
For axis = 3 To 30
For add = 4 To 40
Console.WriteLine("{0} , {1},{2},{3} ", _
sphere, cylinder, axis, add)
Next add
Next axis
Next cylinder
Next sphere
Run Code Online (Sandbox Code Playgroud)
我需要将这个程序的输出导出为CSV格式......任何人都可以通过给出相同的代码来帮助我.......
我在java中编写了一个非常简单的程序,用于使用static关键字.但我得到输出为0.我无法找到原因.我是java的初学者.任何人都可以建议一个解决方案,也请解释为什么遇到这样的问题...我的代码如下:
public class Cube{
static int length;
static int breadth;
static int height;
public static int volume(final int i, final int j, final int k){
return length * breadth * height;
}
public static void main(final String args[]){
System.out
.println("volume of the cube is : " + Cube.volume(10, 20, 30));
}
}
Run Code Online (Sandbox Code Playgroud) 我想避免使用for循环来迭代HaspMap以找到一个键,然后拿起对应于该键的值...任何人都可以帮我实现相同的......?下面给出的是我使用forloop的代码,我想用containsKey函数替换()
for (Entry<Long, Long> entry : sessionTimeStampHash.entrySet())
//if(sessionTimeStampHash.containsKey(sessionID))
{
if (entry.getKey().equals(sessionID))
{
sessionTimeStamp = entry.getValue();
}
}
Run Code Online (Sandbox Code Playgroud) 我试图将xml存储到字符串中.这在C++中真的可行吗?我收到了一个反复的错误:
error: parse error before string constant
Run Code Online (Sandbox Code Playgroud)
在尝试编写一行代码时如下:
string xmlString = "<animalList dnPrefix="String">
<node>
<animal ID="xxxxxxxx">
<Status>managed</Status>
<Type>ENB</Type>
<Subtype>0</Subtype>
<Version1>0.0</Version1>
<Version2>0.0</Version2>
<Name>ChicagoWest5678</Name>
<LocalName>ChicagoWest5678</LocalName>
</animal>
<animal ID ="yyyyyy">
<Status>managed</Status>
<Type>ENB</Type>
<Subtype>0</Subtype>
<Version1>0.0</Version1>
<Version2>0.0</Version2>
<Name>ChicagoWest5678</Name>
<LocalName>ChicagoWest5678</LocalName>
</animal>
</node>
</animalList> ";
Run Code Online (Sandbox Code Playgroud)
除了将它保存到文件之外还有其他任何方式..?我不能直接将它存储到一个字符串中..请帮帮我朋友...
有没有什么办法可以比较两个逗号分隔值的字符串?
说清楚:
string S1 = "a,b,c,d,e"
string S2 = "c,d"
string S3 = "a,b,e" //where string S3 is got by subtracting S2 from S1 (S1 - S2)
Run Code Online (Sandbox Code Playgroud)
是否可以通过某些功能执行此操作?