我有一个任务,我必须加入两个相同类型的列表(客户).他们有类似的条目,我必须避免重复.
这是我的客户类:
class Customer
{
private String _fName, _lName;
private int _age, _cusIndex;
private float _expenses;
public Customer(String fName, String lName, int age, float expenses, int cusIndex)
{
this._fName = fName;
this._lName = lName;
this._age = age;
this._expenses = expenses;
this._cusIndex = cusIndex;
}
}
Run Code Online (Sandbox Code Playgroud)
所以我有两个List<Customer>
名字customers1
和customers2
.我需要在不使用Collections方法的情况下加入这两个方法(比如customer1.Union(customer2).ToList();
使用Linq查询).
这是我写的Linq查询:
var joined = (from c1 in customers1
join c2 in customers2
on c1.CusIndex equals c2.CusIndex
select new {c1, c2});
Run Code Online (Sandbox Code Playgroud)
但是这给了我出现在两个列表上的成员.但我需要所有人,而不是重复.有什么办法吗?
有没有办法转换string
到json
芭蕾舞女演员?
我发现这个PR - 添加jsons:parse()方法从一个字符串中获取一个JSON,它表示添加支持解析string
为json
,但找不到任何示例.
我尝试了以下方法:
string person = {"name":"John", "address":{"number":89, "street":"main street", "town": "Colombo"}};
json personJson = sons:parse(person);
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误:
undefined package 'jsons'
undefined function 'parse'
Run Code Online (Sandbox Code Playgroud) 卡夫卡版本:0.9.0.1
如果n = 20
,我必须获取某个主题的最后 20 条消息。
我试过
kafkaConsumer.seekToBeginning();
Run Code Online (Sandbox Code Playgroud)
但它检索所有消息。我只需要获取最后 20 条消息。
这个话题可能有几十万条记录
public List<JSONObject> consumeMessages(String kafkaTopicName) {
KafkaConsumer<String, String> kafkaConsumer = null;
boolean flag = true;
List<JSONObject> messagesFromKafka = new ArrayList<>();
int recordCount = 0;
int i = 0;
int maxMessagesToReturn = 20;
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("group.id", "project.group.id");
props.put("max.partition.fetch.bytes", "1048576000");
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
kafkaConsumer = new KafkaConsumer<>(props);
kafkaConsumer.subscribe(Arrays.asList(kafkaTopicName));
TopicPartition topicPartition = new TopicPartition(kafkaTopicName, 0);
LOGGER.info("Subscribed to topic " + kafkaConsumer.listTopics());
while (flag) { …
Run Code Online (Sandbox Code Playgroud) 我们有一个带有 3 个 kafka 代理的 HDP 集群(来自 hortonworks)
我们想运行 kafka 控制台消费者,以便从具有特定偏移量的主题中获取一条消息
/usr/hdp/current/kafka-broker/bin/kafka-console-consumer.sh --zookeeper zoo01:2181 --topic lopet.lo.pm--partition 0 --offset 34537263 --max-messages 1
Run Code Online (Sandbox Code Playgroud)
但我们得到以下信息:
我们错在哪里?
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
Partition-offset based consumption is supported in the new consumer only.
Option Description
------ -----------
--blacklist <blacklist> Blacklist of topics to exclude from
consumption.
--bootstrap-server <server to connect REQUIRED (unless …
Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个字符串,11 11
但我面临的问题是我得到start
以下字符串,98 11
而不是11 11
.
我该如何解决这个问题?
我感谢任何帮助.
Character number = newName.charAt(2); //here number is 1
Character numberBefore = newName.charAt(1); //here numberBefore is 1
try (PrintWriter writer = new PrintWriter(path+File.separator+newName);
Scanner scanner = new Scanner(file)) {
boolean shouldPrint = false;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if(numberBefore >0 ){
String start= number+number+" "+number+number; //here start is `98 11`
}
Run Code Online (Sandbox Code Playgroud) 我有一个 C 代码,它调用 ARM Assembly 中定义的函数。必须传递两个参数。
如果函数调用如下所示:
functionName(a, b)
Run Code Online (Sandbox Code Playgroud)
寄存器x0
并按x1
什么顺序保存这些值?是x0
一直持有a
还是一直x1
持有b
,还是相反?
当我运行这个程序时,Client 类会提示用户输入一个命令,该命令应该转到 Server 类并打开一个文件并读取该文件的每一行并将字节长度返回给 Client 类以进行显示。
不幸的是,一旦我输入命令,就没有任何反应并且不知道为什么。
TCP客户端类
package TcpClient;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.Socket;
import java.io.*;
public class TcpClient {
public static void main(String[] args) {
String temp;
String displayBytes;
try {
//create input stream
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
//create client socket, connect to server
Socket clientSocket = new Socket("localhost",5555);
//create output stream attached to socket
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
System.out.print("Command : ");
//create input stream attached to socket
BufferedReader inFromServer =
new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); …
Run Code Online (Sandbox Code Playgroud) 我是C++的新手.我有这个代码来创建一个结构,以显示mutable
C++ 中关键字的用法.
#include <iostream>
using namespace std;
int main()
{
struct
{
mutable double radius;
double PI = 3.142;
double getArea()
{
return (PI * radius * radius);
}
} circle;
const struct circle c1 = {2.0};
circle.radius = 7;
cout << "Area is " << circle.getArea() << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是在编译时我收到以下错误消息:
error: variable const main()::circle c1 has initializer but incomplete type
Run Code Online (Sandbox Code Playgroud)
错误在于c1
该行const struct circle c1 = {2.0};
.任何人都可以在这里指出我的错误.
我有一个方法,它有一个 varargs 参数。它看起来像这样:
public void sampleFunction(String name, Object... args) {
}
Run Code Online (Sandbox Code Playgroud)
我想将 a 传递byte[]
给此方法,但作为单个参数。我怎样才能做到这一点?
byte[] myByteArray = functionReturningAByteArray();
sampleFunction("Name", myByteArray);
Run Code Online (Sandbox Code Playgroud)
这会被视为一个数组,还是会myByteArray
被视为一个单一的对象?
当我通过时byte[]
,IntelliJ 将其报告为Confusing primitive array argument to varargs method
. 我试图按照它的建议转换myByteArray
为 an Object
,然后它报告它为多余的转换。
我想将它作为单个对象传递。
我们可以在不使用二元运算的情况下在 OCaml 中找到 inter 的符号吗?我的意思是很容易通过与 0 进行比较来获得符号。除了使用 match with command 之外,还有其他方法吗?我尝试了以下
let sign n =
let k = abs(n) in
match k with
| 0 -> 0
| n -> 1
| _ -> (-1);;
Run Code Online (Sandbox Code Playgroud)
但它不适用于负数,因为它表明最后一次比较未使用。:/
我有一个int
例子:
151515
1
1111111
4848484
111
888
Run Code Online (Sandbox Code Playgroud)
我需要测试/检查数字是否仅包含1,有效示例:
1
11111
1111111111
11
Run Code Online (Sandbox Code Playgroud)
示例无效:
88888888888
8885555
4747
7
889
Run Code Online (Sandbox Code Playgroud)
有什么建议?可能是任何regex
?或者有一个没有正则表达式的快速解决方案,并将值保留为int而不将其解析为String.
public static void main(String[] args)throws IOException {
String s ="12312a";
int x = Integer.parseInt(s);
System.out.println (x+2);
}
Run Code Online (Sandbox Code Playgroud)
而我所拥有的只是:
Exception in thread "main" java.lang.NumberFormatException: For input string: "12312a"
任何提示?