java创建列表_如何用Java创建新列表

让我总结一下并添加一些内容:

JDK

1. new ArrayList();

2. Arrays.asList("A", "B", "C")

番石榴

1. Lists.newArrayList("Mike", "John", "Lesly");

2. Lists.asList("A","B", new String [] {"C", "D"});

不可变列表

1. Collections.unmodifiableList(new ArrayList(Arrays.asList("A","B")));

2. ImmutableList.builder()                                      // Guava

.add("A")

.add("B").build();

3. ImmutableList.of("A", "B");                                  // Guava

4. ImmutableList.copyOf(Lists.newArrayList("A", "B", "C"));     // Guava

空的不可变列表

1. Collections.emptyList();

2. Collections.EMPTY_LIST;

字符列表

1. Lists.charactersOf("String")                                 // Guava

2. Lists.newArrayList(Splitter.fixedLength(1).split("String"))  // Guava

整数列表

Ints.asList(1,2,3);                                             // Guava

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以帮你回答这个问题。 使用Java客户端创建索引和映射,需要连接Elasticsearch服务器,并使用Elasticsearch Java API进行操作。以下是一个简单的示例代码,用于创建索引和映射: ```java import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import java.io.IOException; public class ElasticSearchIndexAndMapping { private static final String INDEX_NAME = "example_index"; private static final String TYPE_NAME = "example_type"; public static void main(String[] args) throws IOException { RestHighLevelClient client = new RestHighLevelClient(/* your Elasticsearch client configuration */); // Create index request CreateIndexRequest request = new CreateIndexRequest(INDEX_NAME); // Create index mapping XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); { builder.startObject("properties"); { builder.startObject("field1"); { builder.field("type", "text"); } builder.endObject(); } builder.endObject(); } builder.endObject(); // Put mapping request PutMappingRequest mappingRequest = new PutMappingRequest(INDEX_NAME); mappingRequest.type(TYPE_NAME); mappingRequest.source(builder); // Execute requests client.indices().create(request, RequestOptions.DEFAULT); client.indices().putMapping(mappingRequest, RequestOptions.DEFAULT); client.close(); } } ``` 在此示例中,我们使用了 `CreateIndexRequest` 和 `PutMappingRequest` 类来创建索引和映射。我们首先创建了一个名为 `example_index` 的索引,并指定了一个名为 `example_type` 的类型。然后,我们使用 `XContentBuilder` 来构建映射。在此示例中,我们只创建了一个名为 `field1` 的字段,并将其类型设置为 `text`。最后,我们使用 `RestHighLevelClient` 来执行创建索引和映射的请求。 请注意,以上示例仅表示如何创建索引和映射。如果您需要更详细的功能,例如添加文档或查询索引,请查看Elasticsearch Java API文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值