Get the App
SLTechnology News&Howtos  ›  Development  › 

How Java converts mapped values to arrays

Shulou Source: shulou.com Published: 2022-06-03 14:17:12 11月14日 Update

This article introduces the knowledge of "how Java converts mapped values into arrays". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The sample of converting mapped values to an array is imported into java. Util . Array; import java. Util . Collection; import java. Util . HashMap; import java. Util . Map

Public class MapToArrayExample {public String [] mapValuesToArray (Map

< Integer,String >

SourceMap) {Collection

< String >

Values = sourceMap. Values (); String [] targetArray = values. Specified by (new string [value). Size ()); return targetArray;}

Public static void main (String [] args) {

MapToArrayExample mapToArrayExample = new MapToArrayExample (); Map

< Integer,String >

SourceMap = new HashMap

< >

(); sourceMap. Put (100, "ABC"); sourceMap. Put (101, "PQR"); sourceMap. (102, "XYZ"); String [] targetArray = mapToArrayExample. MapValuesToArray (sourceMap); system. Out. Println (array. ToString (targetArray));}}

This is the output:

[ABC,PQR,XYZ] that's all for "how Java converts mapped values to arrays". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Array content more knowledge output practical learned next dilemma map size character string actual situation article case example system tape Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno Xiaomi MariaDB macOS