Search This Blog

Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

Friday, September 25, 2020

Java Contains Byte String - Back to Original Content String from Byte Array String

Code


String str = "hello";
byte [] x = str.getBytes ();
System.out.println ( new String (x) );
String byStr = "104, 101, 108, 108, 111";
String a [] = byStr.split ( "," );
byte xx [] = new byte[a.length];
int count = 0;
for ( String s :  a)
{
xx[count++] = Byte.parseByte ( s.trim () );
}
System.out.println ( new String (xx) );


Output

hello

hello




Monday, June 8, 2020

Python Array of Array - Inner Array processing

#Program -1, To print array of array 
 
a = [[{'Key': 'key700', 'Value': 'val145'}, {'Key': 'key123', 'Value': 'val123'}]]

for i in range(len(a)):
    for j in range(len(a[i])):
        jsonData = a[i][j]
        #print(jsonData);
        for (k, v) in jsonData.items():
            print("Key: " + k)
            print("Value: " + str(v))

   


'''
output
********
Key: Key
Value: key700
Key: Value
Value: val145
Key: Key
Value: Key123
Key: Value
Value: val123

'''


#Program -2 , print only the key=userName

import json

a = [[{'Key': 'age', 'Value': '10'}, {'Key': 'userName', 'Value': 'vijay'}, {'Key': 'address', 'Value': '1, car st'}, {'Key': 'userName', 'Value': 'pranika'}]]

for i in range(len(a)):
    for j in range(len(a[i])):
        jsonData = a[i][j]
        data = json.loads(json.dumps(jsonData ) );
        if ( jsonData['Key'] == 'Name' ):
            print ( jsonData['Value'] )

           
       
   


'''
output
********
vijay
pranika
'''

 

Wednesday, May 8, 2019

ObjectMapper - read JSON list to VO object

ObjectMapper mapper = new ObjectMapper ();

mapper.enable ( DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY );
mapper.configure ( JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true );

List queryBuilderVOList = Arrays.asList ( mapper.readValue ( mapper.writeValueAsString ( map.get ( "data" ) ).getBytes (), QueryBuilderVO [].class ) );

Hit Counter


View My Stats